Advertisement
iyera20

Piezo and Photoresistor

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