Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int light = 0; //Store Light Sensor Reading
- float frequency = 0; //float variable for frequency value
- void setup()
- {
- // Initiate Serial communication
- Serial.begin(9600);
- pinMode(9, OUTPUT);
- pinMode(A0, INPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- light = analogRead(A0); //set light to be the input from light sensor
- Serial.println(light); //print out light value
- //map the light sensor values to a frequency value between 100 and 1000
- frequency = map(light, 120, 900, 10, 1000);
- tone(9, frequency, 100);
- tone(9, frequency, 200);
- tone(9, frequency, 300);
- tone(9, frequency, 400);
- tone(9, frequency, 500);
- tone(9, frequency, 600);
- tone(9, frequency, 700);
- tone(9, frequency, 800);
- tone(9, frequency, 900);
- tone(9, frequency, 1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement