SHARE
TWEET

Untitled

a guest Feb 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int light = 0; //Store Light Sensor Reading
  2. float frequency = 0; //float variable for frequency value
  3.  
  4.  
  5. void setup()
  6. {
  7.   // Initiate Serial communication
  8.   Serial.begin(9600);
  9.  
  10.   pinMode(9, OUTPUT);
  11.   pinMode(A0, INPUT);
  12. }
  13.  
  14. void loop() {
  15.   // put your main code here, to run repeatedly:
  16.  
  17.   light = analogRead(A0); //set light to be the input from light sensor
  18.  
  19.   Serial.println(light);  //print out light value
  20.  
  21.   //map the light sensor values to a frequency value between 100 and 1000
  22.   frequency = map(light, 120, 900, 10, 1000);
  23.  
  24.   tone(9, frequency, 100);
  25.   tone(9, frequency, 200);
  26.   tone(9, frequency, 300);
  27.   tone(9, frequency, 400);
  28.   tone(9, frequency, 500);
  29.   tone(9, frequency, 600);
  30.   tone(9, frequency, 700);
  31.   tone(9, frequency, 800);
  32.   tone(9, frequency, 900);
  33.   tone(9, frequency, 1000);
  34.  
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top