Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. // Project name: arduino- klavesovy hudobny nastroj
  2. // Creators: Daniel Kupka, Samuel Valencik, Katarina Drabikova
  3.  
  4. // 8 octaves
  5. int tone_C = 2;
  6. int tone_D = 3;
  7. int tone_E = 4;
  8. int tone_F = 5;
  9. int tone_G = 6;
  10. int tone_A = 7;
  11. int tone_B = 8;
  12. int toneC = 9;
  13.  
  14.  
  15.  
  16. // buzzer piezo
  17. int buzzer = 13;
  18.  
  19. //set status of button at 0
  20. int status_C = 0;
  21. int status_D = 0;
  22. int status_E = 0;
  23. int status_F = 0;
  24. int status_G = 0;
  25. int status_A = 0;
  26. int status_B = 0;
  27. int statusC = 0;
  28.  
  29.  
  30. //notes 'c' , 'd', 'e', 'f', 'g', 'a', 'b', 'C'
  31. int tones[] = { 200, 240, 280, 320, 360, 400, 440, 480 }; //freqencies
  32. int ThisTone = 0;
  33. //moje
  34.  
  35.  
  36. const int button_Start = 10;//pin on button
  37. const int ledStop = 11;
  38. const int ledStart = 12;
  39.  
  40.  
  41. int status_Start = 0; //status strtu
  42. int starter = 0; //change start stop cycle
  43. bool stat; //start/stop
  44.  
  45.  
  46. void setup() {
  47.  
  48. pinMode(tone_C, INPUT);
  49. pinMode(tone_D, INPUT);
  50. pinMode(tone_E, INPUT);
  51. pinMode(tone_F, INPUT);
  52. pinMode(tone_G, INPUT);
  53. pinMode(tone_A, INPUT);
  54. pinMode(tone_B, INPUT);
  55. pinMode(toneC, INPUT);
  56.  
  57. pinMode(buzzer, OUTPUT);
  58.  
  59. pinMode(button_Start, INPUT);
  60.  
  61. pinMode(ledStop, OUTPUT);
  62. pinMode(ledStart, OUTPUT);
  63.  
  64. stat = false;
  65.  
  66. }
  67.  
  68. void loop() {
  69. status_Start = digitalRead(button_Start);
  70.  
  71. if (status_Start == HIGH)
  72. {
  73. while (status_Start == HIGH) {
  74.  
  75. }
  76. starter++;
  77. }
  78.  
  79. stat = starter % 2;
  80.  
  81. if (stat == true) {
  82. digitalWrite(ledStop, LOW);
  83. digitalWrite(ledStart, HIGH);
  84. //tvoj kod
  85. {
  86. status_C = digitalRead(tone_C);
  87. status_D = digitalRead(tone_D);
  88. status_E = digitalRead(tone_E);
  89. status_F = digitalRead(tone_F);
  90. status_G = digitalRead(tone_G);
  91. status_A = digitalRead(tone_A);
  92. status_B = digitalRead(tone_B);
  93. statusC = digitalRead(toneC);
  94.  
  95.  
  96. //in case button is pressed play specific tone
  97.  
  98.  
  99. if ((status_C == HIGH) || (status_E == HIGH) ||
  100. (status_G == HIGH) || (status_D == HIGH) ||
  101. (status_F == HIGH) || (status_A == HIGH) ||
  102. (status_B == HIGH) || (statusC == HIGH) )
  103. {
  104. if (status_C == HIGH)
  105. {
  106. ThisTone = tones[0];
  107.  
  108. }
  109. if (status_E == HIGH)
  110. {
  111. ThisTone = tones[1];
  112. }
  113. if (status_G == HIGH)
  114. {
  115. ThisTone = tones[2];
  116. }
  117. if (status_D == HIGH)
  118. {
  119. ThisTone = tones[3];
  120. }
  121. if (status_F == HIGH)
  122. {
  123. ThisTone = tones[4];
  124. }
  125. if (status_A == HIGH)
  126. {
  127. ThisTone = tones[5];
  128. }
  129. if (status_B == HIGH)
  130. {
  131. ThisTone = tones[6];
  132. }
  133. if (statusC == HIGH)
  134. {
  135. ThisTone = tones[7];
  136. }
  137.  
  138. digitalWrite(buzzer, HIGH);
  139. delayMicroseconds(ThisTone);
  140. digitalWrite(buzzer, LOW);
  141. delayMicroseconds(ThisTone);
  142. }
  143. //in case no button is pressed turn the buzzer off
  144. else
  145. {
  146. digitalWrite(buzzer, LOW);
  147. }
  148.  
  149. }
  150. //konec dana
  151. } else {
  152. digitalWrite(ledStop, HIGH);
  153. digitalWrite(ledStart, LOW);
  154.  
  155. }
  156.  
  157.  
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement