Advertisement
manvi_m

piezo with photoresistor

Jun 25th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. /*
  2. * Manvi Mittal
  3. * Piezo intro
  4. */
  5.  
  6. const int photoPin = A0;
  7. const int piezoPin = 8;
  8. int photoVal = 0;
  9. int mini = 0;
  10. int maxi = 300;
  11.  
  12. void setup() {
  13. // put your setup code here, to run once:
  14. pinMode (photoPin, INPUT);
  15. pinMode (piezoPin, OUTPUT);
  16. Serial.begin (9600);
  17. }
  18.  
  19. void loop() {
  20. // put your main code here, to run repeatedly:
  21. photoVal = analogRead (photoPin);
  22. Serial.println (photoVal);
  23. photoVal = map (photoVal, mini, maxi, 130, 930);
  24. tone (piezoPin, photoVal, 20);
  25. delay (20);
  26. noTone (piezoPin);
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement