Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. #include "pitches.h"
  2.  
  3. //A
  4. int buttonPin2 = 2;
  5. int Anote = NOTE_A3;
  6. int ADurat = 8;
  7.  
  8. //B
  9. int buttonPin3 = 3;
  10. int Bnote = NOTE_B3;
  11. int BDurat = 8;
  12.  
  13. //C
  14. int buttonPin4 = 4;
  15. int Cnote = NOTE_C4;
  16. int CDurat = 8;
  17.  
  18. //D
  19. int buttonPin5 = 5;
  20. int Dnote = NOTE_D4;
  21. int DDurat = 8;
  22.  
  23. //E
  24. int buttonPin6 = 6;
  25. int Enote = NOTE_E4;
  26. int EDurat = 8;
  27.  
  28. //F
  29. int buttonPin7 = 7;
  30. int Fnote = NOTE_F4;
  31. int FDurat = 8;
  32.  
  33. //G
  34. int buttonPin8 = 8;
  35. int Gnote = NOTE_G4;
  36. int GDurat = 8;
  37.  
  38. void setup(){
  39. pinMode(buttonPin2, INPUT);
  40. pinMode(buttonPin3, INPUT);
  41. pinMode(buttonPin4, INPUT);
  42. pinMode(buttonPin5, INPUT);
  43. pinMode(buttonPin6, INPUT);
  44. pinMode(buttonPin7, INPUT);
  45. pinMode(buttonPin8, INPUT);
  46. }
  47.  
  48. void loop(){
  49.  
  50. int buttonState2 = digitalRead(buttonPin2); //A
  51. int buttonState3 = digitalRead(buttonPin3); //B
  52. int buttonState4 = digitalRead(buttonPin4); //C
  53. int buttonState5 = digitalRead(buttonPin5); //D
  54. int buttonState6 = digitalRead(buttonPin6); //E
  55. int buttonState7 = digitalRead(buttonPin7); //F
  56. int buttonState8 = digitalRead(buttonPin8); //G
  57.  
  58. //A
  59. if (buttonState2 == 1){
  60.  
  61. int noteDuration = 2000 / ADurat;
  62. tone(12, Anote, noteDuration);
  63. int pauseBetweenNotes = noteDuration * 1.30;
  64. delay(pauseBetweenNotes);
  65. }
  66.  
  67. //B
  68. if (buttonState3 == 1){
  69. int noteDuration = 2000 / BDurat;
  70. tone(12, Bnote, noteDuration);
  71. int pauseBetweenNotes = noteDuration * 1.30;
  72. delay(pauseBetweenNotes);
  73.  
  74. }
  75.  
  76.  
  77.  
  78. //C
  79. if (buttonState4 == 1){
  80.  
  81. int noteDuration = 2000 / CDurat;
  82. tone(12, Cnote, noteDuration);
  83. int pauseBetweenNotes = noteDuration * 1.30;
  84. delay(pauseBetweenNotes);
  85. }
  86.  
  87.  
  88. //D
  89. if (buttonState5 == 1){
  90.  
  91. int noteDuration = 2000 / DDurat;
  92. tone(12, Dnote, noteDuration);
  93. int pauseBetweenNotes = noteDuration * 1.30;
  94. delay(pauseBetweenNotes);
  95. }
  96.  
  97.  
  98. //E
  99. if (buttonState6 == 1){
  100.  
  101. int noteDuration = 2000 / EDurat;
  102. tone(12, Enote, noteDuration);
  103. int pauseBetweenNotes = noteDuration * 1.30;
  104. delay(pauseBetweenNotes);
  105. }
  106.  
  107.  
  108. //F
  109. if (buttonState7 == 1){
  110.  
  111. int noteDuration = 2000 / FDurat;
  112. tone(12, Fnote, noteDuration);
  113. int pauseBetweenNotes = noteDuration * 1.30;
  114. delay(pauseBetweenNotes);
  115. }
  116.  
  117. //G
  118. if (buttonState8 == 1){
  119.  
  120. int noteDuration = 2000 / GDurat;
  121. tone(12, Gnote, noteDuration);
  122. int pauseBetweenNotes = noteDuration * 1.30;
  123. delay(pauseBetweenNotes);
  124. }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement