daniel_lawson9999

Daniel Lawson 4 keyboard

Oct 18th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1.  
  2. int notes[] = {262,294,330,349};
  3.  
  4. const int buttonRead = A0;
  5. const int piezo = 8;
  6. void setup()
  7. {
  8. Serial.begin(9600);
  9.  
  10. }
  11.  
  12. void loop()
  13. {
  14. int keyVal = analogRead(buttonRead);
  15. Serial.println(keyVal);
  16.  
  17. if (keyVal >= 1020 && keyVal <= 1023)
  18. {
  19. tone(piezo, notes[0]);
  20. }
  21.  
  22. else if (keyVal >= 990 && keyVal <= 1010)
  23. {
  24.  
  25. tone(piezo,notes[1]);
  26. }
  27. else if(keyVal >= 505 && keyVal <= 515)
  28. {
  29. tone(piezo,notes[2]);
  30. }
  31. else if(keyVal >= 5 && keyVal <= 10)
  32. {
  33. tone(piezo,notes[3]);
  34. }
  35.  
  36. else
  37. {
  38. noTone(piezo);
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment