Code: Change Tone according to light

/*
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
This example code is in the public domain. http://arduino.cc/en/Tutorial/Tone2

*/


void setup() {
Serial.begin(9600);
}

void loop() {
int sensorReading = analogRead(0);
Serial.println(sensorReading);
int thisPitch = map(sensorReading, 400, 1000, 100, 1000);

tone(8, thisPitch, 10);

}





Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.