4
Plays a pitch that changes based on a changing analog input
7
* 8-ohm speaker on digital pin 8
8
* photoresistor on analog 0 to 5V
9
* 4.7K resistor on analog 0 to ground
15
This example code is in the public domain.
17
http://arduino.cc/en/Tutorial/Tone2
23
// initialize serial communications (for debugging only):
29
int sensorReading = analogRead(A0);
30
// print the sensor reading so you know its range
31
Serial.println(sensorReading);
32
// map the pitch to the range of the analog input.
33
// change the minimum and maximum input numbers below
34
// depending on the range your sensor's giving:
35
int thisPitch = map(sensorReading, 400, 1000, 100, 1000);
38
tone(9, thisPitch, 10);