arduino-0018-windows
This commit is contained in:
parent
157fd6f1a1
commit
f39fc49523
5182 changed files with 950586 additions and 0 deletions
40
arduino-0018-windows/examples/Digital/Blink/Blink.pde
Normal file
40
arduino-0018-windows/examples/Digital/Blink/Blink.pde
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
Blink
|
||||
|
||||
Turns on an LED on for one second, then off for one second, repeatedly.
|
||||
|
||||
The circuit:
|
||||
* LED connected from digital pin 13 to ground.
|
||||
|
||||
* Note: On most Arduino boards, there is already an LED on the board
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
|
||||
Created 1 June 2005
|
||||
By David Cuartielles
|
||||
|
||||
http://arduino.cc/en/Tutorial/Blink
|
||||
|
||||
based on an orginal by H. Barragan for the Wiring i/o board
|
||||
|
||||
*/
|
||||
|
||||
int ledPin = 13; // LED connected to digital pin 13
|
||||
|
||||
// The setup() method runs once, when the sketch starts
|
||||
|
||||
void setup() {
|
||||
// initialize the digital pin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
// the loop() method runs over and over again,
|
||||
// as long as the Arduino has power
|
||||
|
||||
void loop()
|
||||
{
|
||||
digitalWrite(ledPin, HIGH); // set the LED on
|
||||
delay(1000); // wait for a second
|
||||
digitalWrite(ledPin, LOW); // set the LED off
|
||||
delay(1000); // wait for a second
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/* Blink without Delay
|
||||
|
||||
Turns on and off a light emitting diode(LED) connected to a digital
|
||||
pin, without using the delay() function. This means that other code
|
||||
can run at the same time without being interrupted by the LED code.
|
||||
|
||||
The circuit:
|
||||
* LED attached from pin 13 to ground.
|
||||
* Note: on most Arduinos, there is already an LED on the board
|
||||
that's attached to pin 13, so no hardware is needed for this example.
|
||||
|
||||
|
||||
created 2005
|
||||
by David A. Mellis
|
||||
modified 17 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
|
||||
*/
|
||||
|
||||
// constants won't change. Used here to
|
||||
// set pin numbers:
|
||||
const int ledPin = 13; // the number of the LED pin
|
||||
|
||||
// Variables will change:
|
||||
int ledState = LOW; // ledState used to set the LED
|
||||
long previousMillis = 0; // will store last time LED was updated
|
||||
|
||||
// the follow variables is a long because the time, measured in miliseconds,
|
||||
// will quickly become a bigger number than can be stored in an int.
|
||||
long interval = 1000; // interval at which to blink (milliseconds)
|
||||
|
||||
void setup() {
|
||||
// set the digital pin as output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// here is where you'd put code that needs to be running all the time.
|
||||
|
||||
// check to see if it's time to blink the LED; that is, is the difference
|
||||
// between the current time and last time we blinked the LED bigger than
|
||||
// the interval at which we want to blink the LED.
|
||||
if (millis() - previousMillis > interval) {
|
||||
// save the last time you blinked the LED
|
||||
previousMillis = millis();
|
||||
|
||||
// if the LED is off turn it on and vice-versa:
|
||||
if (ledState == LOW)
|
||||
ledState = HIGH;
|
||||
else
|
||||
ledState = LOW;
|
||||
|
||||
// set the LED with the ledState of the variable:
|
||||
digitalWrite(ledPin, ledState);
|
||||
}
|
||||
}
|
54
arduino-0018-windows/examples/Digital/Button/Button.pde
Normal file
54
arduino-0018-windows/examples/Digital/Button/Button.pde
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
Button
|
||||
|
||||
Turns on and off a light emitting diode(LED) connected to digital
|
||||
pin 13, when pressing a pushbutton attached to pin 7.
|
||||
|
||||
|
||||
The circuit:
|
||||
* LED attached from pin 13 to ground
|
||||
* pushbutton attached to pin 2 from +5V
|
||||
* 10K resistor attached to pin 2 from ground
|
||||
|
||||
* Note: on most Arduinos there is already an LED on the board
|
||||
attached to pin 13.
|
||||
|
||||
|
||||
created 2005
|
||||
by DojoDave <http://www.0j0.org>
|
||||
modified 17 Jun 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Button
|
||||
*/
|
||||
|
||||
// constants won't change. They're used here to
|
||||
// set pin numbers:
|
||||
const int buttonPin = 2; // the number of the pushbutton pin
|
||||
const int ledPin = 13; // the number of the LED pin
|
||||
|
||||
// variables will change:
|
||||
int buttonState = 0; // variable for reading the pushbutton status
|
||||
|
||||
void setup() {
|
||||
// initialize the LED pin as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
// initialize the pushbutton pin as an input:
|
||||
pinMode(buttonPin, INPUT);
|
||||
}
|
||||
|
||||
void loop(){
|
||||
// read the state of the pushbutton value:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
// check if the pushbutton is pressed.
|
||||
// if it is, the buttonState is HIGH:
|
||||
if (buttonState == HIGH) {
|
||||
// turn LED on:
|
||||
digitalWrite(ledPin, HIGH);
|
||||
}
|
||||
else {
|
||||
// turn LED off:
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
}
|
74
arduino-0018-windows/examples/Digital/Debounce/Debounce.pde
Normal file
74
arduino-0018-windows/examples/Digital/Debounce/Debounce.pde
Normal file
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
Debounce
|
||||
|
||||
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
|
||||
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
|
||||
a minimum delay between toggles to debounce the circuit (i.e. to ignore
|
||||
noise).
|
||||
|
||||
The circuit:
|
||||
* LED attached from pin 13 to ground
|
||||
* pushbutton attached from pin 2 to +5V
|
||||
* 10K resistor attached from pin 2 to ground
|
||||
|
||||
* Note: On most Arduino boards, there is already an LED on the board
|
||||
connected to pin 13, so you don't need any extra components for this example.
|
||||
|
||||
|
||||
created 21 November 2006
|
||||
by David A. Mellis
|
||||
modified 3 Jul 2009
|
||||
by Limor Fried
|
||||
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/Debounce
|
||||
*/
|
||||
|
||||
// constants won't change. They're used here to
|
||||
// set pin numbers:
|
||||
const int buttonPin = 2; // the number of the pushbutton pin
|
||||
const int ledPin = 13; // the number of the LED pin
|
||||
|
||||
// Variables will change:
|
||||
int ledState = HIGH; // the current state of the output pin
|
||||
int buttonState; // the current reading from the input pin
|
||||
int lastButtonState = LOW; // the previous reading from the input pin
|
||||
|
||||
// the following variables are long's because the time, measured in miliseconds,
|
||||
// will quickly become a bigger number than can be stored in an int.
|
||||
long lastDebounceTime = 0; // the last time the output pin was toggled
|
||||
long debounceDelay = 50; // the debounce time; increase if the output flickers
|
||||
|
||||
void setup() {
|
||||
pinMode(buttonPin, INPUT);
|
||||
pinMode(ledPin, OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the state of the switch into a local variable:
|
||||
int reading = digitalRead(buttonPin);
|
||||
|
||||
// check to see if you just pressed the button
|
||||
// (i.e. the input went from LOW to HIGH), and you've waited
|
||||
// long enough since the last press to ignore any noise:
|
||||
|
||||
// If the switch changed, due to noise or pressing:
|
||||
if (reading != lastButtonState) {
|
||||
// reset the debouncing timer
|
||||
lastDebounceTime = millis();
|
||||
}
|
||||
|
||||
if ((millis() - lastDebounceTime) > debounceDelay) {
|
||||
// whatever the reading is at, it's been there for longer
|
||||
// than the debounce delay, so take it as the actual current state:
|
||||
buttonState = reading;
|
||||
}
|
||||
|
||||
// set the LED using the state of the button:
|
||||
digitalWrite(ledPin, buttonState);
|
||||
|
||||
// save the reading. Next time through the loop,
|
||||
// it'll be the lastButtonState:
|
||||
lastButtonState = reading;
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
State change detection (edge detection)
|
||||
|
||||
Often, you don't need to know the state of a digital input all the time,
|
||||
but you just need to know when the input changes from one state to another.
|
||||
For example, you want to know when a button goes from OFF to ON. This is called
|
||||
state change detection, or edge detection.
|
||||
|
||||
This example shows how to detect when a button or button changes from off to on
|
||||
and on to off.
|
||||
|
||||
The circuit:
|
||||
* pushbutton attached to pin 2 from +5V
|
||||
* 10K resistor attached to pin 2 from ground
|
||||
* LED attached from pin 13 to ground (or use the built-in LED on
|
||||
most Arduino boards)
|
||||
|
||||
created 27 Sep 2005
|
||||
modified 30 Dec 2009
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/ButtonStateChange
|
||||
|
||||
*/
|
||||
|
||||
// this constant won't change:
|
||||
const int buttonPin = 2; // the pin that the pushbutton is attached to
|
||||
const int ledPin = 13; // the pin that the LED is attached to
|
||||
|
||||
// Variables will change:
|
||||
int buttonPushCounter = 0; // counter for the number of button presses
|
||||
int buttonState = 0; // current state of the button
|
||||
int lastButtonState = 0; // previous state of the button
|
||||
|
||||
void setup() {
|
||||
// initialize the button pin as a input:
|
||||
pinMode(buttonPin, INPUT);
|
||||
// initialize the LED as an output:
|
||||
pinMode(ledPin, OUTPUT);
|
||||
// initialize serial communication:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// read the pushbutton input pin:
|
||||
buttonState = digitalRead(buttonPin);
|
||||
|
||||
// compare the buttonState to its previous state
|
||||
if (buttonState != lastButtonState) {
|
||||
// if the state has changed, increment the counter
|
||||
if (buttonState == HIGH) {
|
||||
// if the current state is HIGH then the button
|
||||
// wend from off to on:
|
||||
buttonPushCounter++;
|
||||
Serial.println("on");
|
||||
Serial.print("number of button pushes: ");
|
||||
Serial.println(buttonPushCounter, DEC);
|
||||
}
|
||||
else {
|
||||
// if the current state is LOW then the button
|
||||
// wend from on to off:
|
||||
Serial.println("off");
|
||||
}
|
||||
|
||||
// save the current state as the last state,
|
||||
//for next time through the loop
|
||||
lastButtonState = buttonState;
|
||||
}
|
||||
|
||||
// turns on the LED every four button pushes by
|
||||
// checking the modulo of the button push counter.
|
||||
// the modulo function gives you the remainder of
|
||||
// the division of two numbers:
|
||||
if (buttonPushCounter % 4 == 0) {
|
||||
digitalWrite(ledPin, HIGH);
|
||||
} else {
|
||||
digitalWrite(ledPin, LOW);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
95
arduino-0018-windows/examples/Digital/toneKeyboard/pitches.h
Normal file
95
arduino-0018-windows/examples/Digital/toneKeyboard/pitches.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*************************************************
|
||||
* Public Constants
|
||||
*************************************************/
|
||||
|
||||
#define NOTE_B0 31
|
||||
#define NOTE_C1 33
|
||||
#define NOTE_CS1 35
|
||||
#define NOTE_D1 37
|
||||
#define NOTE_DS1 39
|
||||
#define NOTE_E1 41
|
||||
#define NOTE_F1 44
|
||||
#define NOTE_FS1 46
|
||||
#define NOTE_G1 49
|
||||
#define NOTE_GS1 52
|
||||
#define NOTE_A1 55
|
||||
#define NOTE_AS1 58
|
||||
#define NOTE_B1 62
|
||||
#define NOTE_C2 65
|
||||
#define NOTE_CS2 69
|
||||
#define NOTE_D2 73
|
||||
#define NOTE_DS2 78
|
||||
#define NOTE_E2 82
|
||||
#define NOTE_F2 87
|
||||
#define NOTE_FS2 93
|
||||
#define NOTE_G2 98
|
||||
#define NOTE_GS2 104
|
||||
#define NOTE_A2 110
|
||||
#define NOTE_AS2 117
|
||||
#define NOTE_B2 123
|
||||
#define NOTE_C3 131
|
||||
#define NOTE_CS3 139
|
||||
#define NOTE_D3 147
|
||||
#define NOTE_DS3 156
|
||||
#define NOTE_E3 165
|
||||
#define NOTE_F3 175
|
||||
#define NOTE_FS3 185
|
||||
#define NOTE_G3 196
|
||||
#define NOTE_GS3 208
|
||||
#define NOTE_A3 220
|
||||
#define NOTE_AS3 233
|
||||
#define NOTE_B3 247
|
||||
#define NOTE_C4 262
|
||||
#define NOTE_CS4 277
|
||||
#define NOTE_D4 294
|
||||
#define NOTE_DS4 311
|
||||
#define NOTE_E4 330
|
||||
#define NOTE_F4 349
|
||||
#define NOTE_FS4 370
|
||||
#define NOTE_G4 392
|
||||
#define NOTE_GS4 415
|
||||
#define NOTE_A4 440
|
||||
#define NOTE_AS4 466
|
||||
#define NOTE_B4 494
|
||||
#define NOTE_C5 523
|
||||
#define NOTE_CS5 554
|
||||
#define NOTE_D5 587
|
||||
#define NOTE_DS5 622
|
||||
#define NOTE_E5 659
|
||||
#define NOTE_F5 698
|
||||
#define NOTE_FS5 740
|
||||
#define NOTE_G5 784
|
||||
#define NOTE_GS5 831
|
||||
#define NOTE_A5 880
|
||||
#define NOTE_AS5 932
|
||||
#define NOTE_B5 988
|
||||
#define NOTE_C6 1047
|
||||
#define NOTE_CS6 1109
|
||||
#define NOTE_D6 1175
|
||||
#define NOTE_DS6 1245
|
||||
#define NOTE_E6 1319
|
||||
#define NOTE_F6 1397
|
||||
#define NOTE_FS6 1480
|
||||
#define NOTE_G6 1568
|
||||
#define NOTE_GS6 1661
|
||||
#define NOTE_A6 1760
|
||||
#define NOTE_AS6 1865
|
||||
#define NOTE_B6 1976
|
||||
#define NOTE_C7 2093
|
||||
#define NOTE_CS7 2217
|
||||
#define NOTE_D7 2349
|
||||
#define NOTE_DS7 2489
|
||||
#define NOTE_E7 2637
|
||||
#define NOTE_F7 2794
|
||||
#define NOTE_FS7 2960
|
||||
#define NOTE_G7 3136
|
||||
#define NOTE_GS7 3322
|
||||
#define NOTE_A7 3520
|
||||
#define NOTE_AS7 3729
|
||||
#define NOTE_B7 3951
|
||||
#define NOTE_C8 4186
|
||||
#define NOTE_CS8 4435
|
||||
#define NOTE_D8 4699
|
||||
#define NOTE_DS8 4978
|
||||
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
keyboard
|
||||
|
||||
Plays a pitch that changes based on a changing analog input
|
||||
|
||||
circuit:
|
||||
* 3 force-sensing resistors from +5V to analog in 0 through 5
|
||||
* 3 10K resistors from analog in 0 through 5 to ground
|
||||
* 8-ohm speaker on digital pin 8
|
||||
|
||||
created 21 Jan 2010
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/Tone3
|
||||
|
||||
*/
|
||||
|
||||
#include "pitches.h"
|
||||
|
||||
const int threshold = 10; // minimum reading of the sensors that generates a note
|
||||
|
||||
// notes to play, corresponding to the 3 sensors:
|
||||
int notes[] = {
|
||||
NOTE_A4, NOTE_B4,NOTE_C3 };
|
||||
|
||||
void setup() {
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
|
||||
// get a sensor reading:
|
||||
int sensorReading = analogRead(thisSensor);
|
||||
|
||||
// if the sensor is pressed hard enough:
|
||||
if (sensorReading > threshold) {
|
||||
// play the note corresponding to this sensor:
|
||||
tone(8, notes[thisSensor], 20);
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
95
arduino-0018-windows/examples/Digital/toneMelody/pitches.h
Normal file
95
arduino-0018-windows/examples/Digital/toneMelody/pitches.h
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*************************************************
|
||||
* Public Constants
|
||||
*************************************************/
|
||||
|
||||
#define NOTE_B0 31
|
||||
#define NOTE_C1 33
|
||||
#define NOTE_CS1 35
|
||||
#define NOTE_D1 37
|
||||
#define NOTE_DS1 39
|
||||
#define NOTE_E1 41
|
||||
#define NOTE_F1 44
|
||||
#define NOTE_FS1 46
|
||||
#define NOTE_G1 49
|
||||
#define NOTE_GS1 52
|
||||
#define NOTE_A1 55
|
||||
#define NOTE_AS1 58
|
||||
#define NOTE_B1 62
|
||||
#define NOTE_C2 65
|
||||
#define NOTE_CS2 69
|
||||
#define NOTE_D2 73
|
||||
#define NOTE_DS2 78
|
||||
#define NOTE_E2 82
|
||||
#define NOTE_F2 87
|
||||
#define NOTE_FS2 93
|
||||
#define NOTE_G2 98
|
||||
#define NOTE_GS2 104
|
||||
#define NOTE_A2 110
|
||||
#define NOTE_AS2 117
|
||||
#define NOTE_B2 123
|
||||
#define NOTE_C3 131
|
||||
#define NOTE_CS3 139
|
||||
#define NOTE_D3 147
|
||||
#define NOTE_DS3 156
|
||||
#define NOTE_E3 165
|
||||
#define NOTE_F3 175
|
||||
#define NOTE_FS3 185
|
||||
#define NOTE_G3 196
|
||||
#define NOTE_GS3 208
|
||||
#define NOTE_A3 220
|
||||
#define NOTE_AS3 233
|
||||
#define NOTE_B3 247
|
||||
#define NOTE_C4 262
|
||||
#define NOTE_CS4 277
|
||||
#define NOTE_D4 294
|
||||
#define NOTE_DS4 311
|
||||
#define NOTE_E4 330
|
||||
#define NOTE_F4 349
|
||||
#define NOTE_FS4 370
|
||||
#define NOTE_G4 392
|
||||
#define NOTE_GS4 415
|
||||
#define NOTE_A4 440
|
||||
#define NOTE_AS4 466
|
||||
#define NOTE_B4 494
|
||||
#define NOTE_C5 523
|
||||
#define NOTE_CS5 554
|
||||
#define NOTE_D5 587
|
||||
#define NOTE_DS5 622
|
||||
#define NOTE_E5 659
|
||||
#define NOTE_F5 698
|
||||
#define NOTE_FS5 740
|
||||
#define NOTE_G5 784
|
||||
#define NOTE_GS5 831
|
||||
#define NOTE_A5 880
|
||||
#define NOTE_AS5 932
|
||||
#define NOTE_B5 988
|
||||
#define NOTE_C6 1047
|
||||
#define NOTE_CS6 1109
|
||||
#define NOTE_D6 1175
|
||||
#define NOTE_DS6 1245
|
||||
#define NOTE_E6 1319
|
||||
#define NOTE_F6 1397
|
||||
#define NOTE_FS6 1480
|
||||
#define NOTE_G6 1568
|
||||
#define NOTE_GS6 1661
|
||||
#define NOTE_A6 1760
|
||||
#define NOTE_AS6 1865
|
||||
#define NOTE_B6 1976
|
||||
#define NOTE_C7 2093
|
||||
#define NOTE_CS7 2217
|
||||
#define NOTE_D7 2349
|
||||
#define NOTE_DS7 2489
|
||||
#define NOTE_E7 2637
|
||||
#define NOTE_F7 2794
|
||||
#define NOTE_FS7 2960
|
||||
#define NOTE_G7 3136
|
||||
#define NOTE_GS7 3322
|
||||
#define NOTE_A7 3520
|
||||
#define NOTE_AS7 3729
|
||||
#define NOTE_B7 3951
|
||||
#define NOTE_C8 4186
|
||||
#define NOTE_CS8 4435
|
||||
#define NOTE_D8 4699
|
||||
#define NOTE_DS8 4978
|
||||
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
Melody
|
||||
|
||||
Plays a melody
|
||||
|
||||
circuit:
|
||||
* 8-ohm speaker on digital pin 8
|
||||
|
||||
created 21 Jan 2010
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/Tone
|
||||
|
||||
*/
|
||||
#include "pitches.h"
|
||||
|
||||
// notes in the melody:
|
||||
int melody[] = {
|
||||
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
|
||||
|
||||
// note durations: 4 = quarter note, 8 = eighth note, etc.:
|
||||
int noteDurations[] = {
|
||||
4, 8, 8, 4,4,4,4,4 };
|
||||
|
||||
void setup() {
|
||||
// iterate over the notes of the melody:
|
||||
for (int thisNote = 0; thisNote < 8; thisNote++) {
|
||||
|
||||
// to calculate the note duration, take one second
|
||||
// divided by the note type.
|
||||
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
|
||||
int noteDuration = 1000/noteDurations[thisNote];
|
||||
tone(8, melody[thisNote],noteDuration);
|
||||
|
||||
// to distinguish the notes, set a minimum time between them.
|
||||
// the note's duration + 30% seems to work well:
|
||||
int pauseBetweenNotes = noteDuration * 1.30;
|
||||
delay(pauseBetweenNotes);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// no need to repeat the melody.
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
Pitch follower
|
||||
|
||||
Plays a pitch that changes based on a changing analog input
|
||||
|
||||
circuit:
|
||||
* 8-ohm speaker on digital pin 8
|
||||
* photoresistor on analog 0 to 5V
|
||||
* 4.7K resistor on analog 0 to ground
|
||||
|
||||
created 21 Jan 2010
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/Tone2
|
||||
|
||||
*/
|
||||
|
||||
|
||||
void setup() {
|
||||
// initialize serial communications (for debugging only):
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the sensor:
|
||||
int sensorReading = analogRead(0);
|
||||
// print the sensor reading so you know its range
|
||||
Serial.println(sensorReading);
|
||||
// map the pitch to the range of the analog input.
|
||||
// change the minimum and maximum input numbers below
|
||||
// depending on the range your sensor's giving:
|
||||
int thisPitch = map(sensorReading, 400, 1000, 100, 1000);
|
||||
|
||||
// play the pitch:
|
||||
tone(8, thisPitch, 10);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in a new issue