top of page

Light Mapped to Tone Code
​int lowValue = 0; //change this number to the lowest value you observed in the last sketch
int highValue = 1023; //change this number to the highest value you observed in the last sketch
void setup() {
Serial.begin(9600); // open serial monitor port
}
void loop() {
int lightValue = analogRead(A0); // reads light intensity
int pitch = map(lightValue, lowValue, highValue, 50, 4000); // maps the light values to a pitch
tone (8, pitch, 15); // play the tone on pin 8 for 15 ms
delay(10); // delay in between reads for stability
}
bottom of page