daniel_lawson9999

Daniel Lawson Piezo with Photoresistor

Oct 15th, 2015
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. int sensorValue;
  2. int sensorLow = 1023;
  3. int sensorHigh = 0;
  4. const int ledPin = 13;
  5. const int photoR = A1;
  6. const int piezo1 = 8;
  7.  
  8.  
  9.  
  10.  
  11.  
  12. void setup()
  13. {
  14. pinMode(ledPin,OUTPUT);
  15. digitalWrite(ledPin, HIGH);
  16.  
  17. while(millis() < 5000)
  18. {
  19. sensorValue = analogRead(photoR);
  20. if (sensorValue > sensorHigh)
  21. {
  22. sensorHigh = sensorValue;
  23. }
  24. if (sensorValue < sensorLow)
  25. {
  26. sensorLow = sensorValue;
  27. }
  28. }
  29.  
  30. digitalWrite(ledPin,LOW);
  31. }
  32.  
  33. void loop()
  34. {
  35. sensorValue = analogRead(photoR);
  36.  
  37. int pitch = map(sensorValue, sensorLow, sensorHigh,50, 4000);
  38.  
  39. tone(piezo1,pitch,20);
  40.  
  41. delay(10);
  42.  
  43.  
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment