Advertisement
coltonspastebin

Piezzo piano with buttons

Feb 6th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. const int activepiezzopin = 11;
  2. const int buttons = A0;
  3. int notes [] = {261, 392, 440, 349};
  4. void setup()
  5. {
  6. pinMode (activepiezzopin, OUTPUT);
  7. pinMode (buttons, INPUT);
  8. Serial.begin (9600);
  9.  
  10. }
  11.  
  12. void loop()
  13. {
  14. int buttonval = analogRead (A0);
  15. Serial.println (buttonval);
  16. if (buttonval > 0 && buttonval < 100)
  17. {
  18. tone (activepiezzopin, notes[0], 200);
  19. }
  20. else if (buttonval > 500 && buttonval < 600)
  21. {
  22. tone (activepiezzopin, notes[1], 200);
  23. }
  24. else if (buttonval > 995 && buttonval < 1010)
  25. {
  26. tone (activepiezzopin, notes[2], 200);
  27. }
  28. else if (buttonval == 1023)
  29. {
  30. tone (activepiezzopin, notes[3], 200);
  31. }
  32. else
  33. {
  34. noTone (activepiezzopin);
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement