document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #define NOTE_B0 31
  2. #define NOTE_C1 33
  3. #define NOTE_CS1 35
  4. #define NOTE_D1 37
  5. #define NOTE_DS1 39
  6. #define NOTE_E1 41
  7. #define NOTE_F1 44
  8. #define NOTE_FS1 46
  9. #define NOTE_G1 49
  10. #define NOTE_GS1 52
  11. #define NOTE_A1 55
  12. #define NOTE_AS1 58
  13. #define NOTE_B1 62
  14. #define NOTE_C2 65
  15. #define NOTE_CS2 69
  16. #define NOTE_D2 73
  17. #define NOTE_DS2 78
  18. #define NOTE_E2 82
  19. #define NOTE_F2 87
  20. #define NOTE_FS2 93
  21. #define NOTE_G2 98
  22. #define NOTE_GS2 104
  23. #define NOTE_A2 110
  24. #define NOTE_AS2 117
  25. #define NOTE_B2 123
  26. #define NOTE_C3 131
  27. #define NOTE_CS3 139
  28. #define NOTE_D3 147
  29. #define NOTE_DS3 156
  30. #define NOTE_E3 165
  31. #define NOTE_F3 175
  32. #define NOTE_FS3 185
  33. #define NOTE_G3 196
  34. #define NOTE_GS3 208
  35. #define NOTE_A3 220
  36. #define NOTE_AS3 233
  37. #define NOTE_B3 247
  38. #define NOTE_C4 262
  39. #define NOTE_CS4 277
  40. #define NOTE_D4 294
  41. #define NOTE_DS4 311
  42. #define NOTE_E4 330
  43. #define NOTE_F4 349
  44. #define NOTE_FS4 370
  45. #define NOTE_G4 392
  46. #define NOTE_GS4 415
  47. #define NOTE_A4 440
  48. #define NOTE_AS4 466
  49. #define NOTE_B4 494
  50. #define NOTE_C5 523
  51. #define NOTE_CS5 554
  52. #define NOTE_D5 587
  53. #define NOTE_DS5 622
  54. #define NOTE_E5 659
  55. #define NOTE_F5 698
  56. #define NOTE_FS5 740
  57. #define NOTE_G5 784
  58. #define NOTE_GS5 831
  59. #define NOTE_A5 880
  60. #define NOTE_AS5 932
  61. #define NOTE_B5 988
  62. #define NOTE_C6 1047
  63. #define NOTE_CS6 1109
  64. #define NOTE_D6 1175
  65. #define NOTE_DS6 1245
  66. #define NOTE_E6 1319
  67. #define NOTE_F6 1397
  68. #define NOTE_FS6 1480
  69. #define NOTE_G6 1568
  70. #define NOTE_GS6 1661
  71. #define NOTE_A6 1760
  72. #define NOTE_AS6 1865
  73. #define NOTE_B6 1976
  74. #define NOTE_C7 2093
  75. #define NOTE_CS7 2217
  76. #define NOTE_D7 2349
  77. #define NOTE_DS7 2489
  78. #define NOTE_E7 2637
  79. #define NOTE_F7 2794
  80. #define NOTE_FS7 2960
  81. #define NOTE_G7 3136
  82. #define NOTE_GS7 3322
  83. #define NOTE_A7 3520
  84. #define NOTE_AS7 3729
  85. #define NOTE_B7 3951
  86. #define NOTE_C8 4186
  87. #define NOTE_CS8 4435
  88. #define NOTE_D8 4699
  89. #define NOTE_DS8 4978
  90.  
  91. #define melodyPin 3
  92. //Mario main theme melody
  93. int melody[] = {
  94. NOTE_E7, NOTE_E7, 0, NOTE_E7,
  95. 0, NOTE_C7, NOTE_E7, 0,
  96. NOTE_G7, 0, 0, 0,
  97. NOTE_G6, 0, 0, 0,
  98.  
  99. NOTE_C7, 0, 0, NOTE_G6,
  100. 0, 0, NOTE_E6, 0,
  101. 0, NOTE_A6, 0, NOTE_B6,
  102. 0, NOTE_AS6, NOTE_A6, 0,
  103.  
  104. NOTE_G6, NOTE_E7, NOTE_G7,
  105. NOTE_A7, 0, NOTE_F7, NOTE_G7,
  106. 0, NOTE_E7, 0, NOTE_C7,
  107. NOTE_D7, NOTE_B6, 0, 0,
  108.  
  109. NOTE_C7, 0, 0, NOTE_G6,
  110. 0, 0, NOTE_E6, 0,
  111. 0, NOTE_A6, 0, NOTE_B6,
  112. 0, NOTE_AS6, NOTE_A6, 0,
  113.  
  114. NOTE_G6, NOTE_E7, NOTE_G7,
  115. NOTE_A7, 0, NOTE_F7, NOTE_G7,
  116. 0, NOTE_E7, 0, NOTE_C7,
  117. NOTE_D7, NOTE_B6, 0, 0
  118. };
  119. //Mario main them tempo
  120. int tempo[] = {
  121. 12, 12, 12, 12,
  122. 12, 12, 12, 12,
  123. 12, 12, 12, 12,
  124. 12, 12, 12, 12,
  125.  
  126. 12, 12, 12, 12,
  127. 12, 12, 12, 12,
  128. 12, 12, 12, 12,
  129. 12, 12, 12, 12,
  130.  
  131. 9, 9, 9,
  132. 12, 12, 12, 12,
  133. 12, 12, 12, 12,
  134. 12, 12, 12, 12,
  135.  
  136. 12, 12, 12, 12,
  137. 12, 12, 12, 12,
  138. 12, 12, 12, 12,
  139. 12, 12, 12, 12,
  140.  
  141. 9, 9, 9,
  142. 12, 12, 12, 12,
  143. 12, 12, 12, 12,
  144. 12, 12, 12, 12,
  145. };
  146. //Underworld melody
  147. int underworld_melody[] = {
  148. NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
  149. NOTE_AS3, NOTE_AS4, 0,
  150. 0,
  151. NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
  152. NOTE_AS3, NOTE_AS4, 0,
  153. 0,
  154. NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
  155. NOTE_DS3, NOTE_DS4, 0,
  156. 0,
  157. NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
  158. NOTE_DS3, NOTE_DS4, 0,
  159. 0, NOTE_DS4, NOTE_CS4, NOTE_D4,
  160. NOTE_CS4, NOTE_DS4,
  161. NOTE_DS4, NOTE_GS3,
  162. NOTE_G3, NOTE_CS4,
  163. NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
  164. NOTE_GS4, NOTE_DS4, NOTE_B3,
  165. NOTE_AS3, NOTE_A3, NOTE_GS3,
  166. 0, 0, 0
  167. };
  168. //Underwolrd tempo
  169. int underworld_tempo[] = {
  170. 12, 12, 12, 12,
  171. 12, 12, 6,
  172. 3,
  173. 12, 12, 12, 12,
  174. 12, 12, 6,
  175. 3,
  176. 12, 12, 12, 12,
  177. 12, 12, 6,
  178. 3,
  179. 12, 12, 12, 12,
  180. 12, 12, 6,
  181. 6, 18, 18, 18,
  182. 6, 6,
  183. 6, 6,
  184. 6, 6,
  185. 18, 18, 18, 18, 18, 18,
  186. 10, 10, 10,
  187. 10, 10, 10,
  188. 3, 3, 3
  189. };
  190.  
  191. void setup(void)
  192. {
  193. pinMode(3, OUTPUT);//buzzer
  194. pinMode(13, OUTPUT);//led indicator when singing a note
  195.  
  196. }
  197. void loop()
  198. {
  199. //sing the tunes
  200. sing(1);
  201. sing(1);
  202. sing(2);
  203. }
  204. int song = 0;
  205.  
  206. void sing(int s) {
  207. // iterate over the notes of the melody:
  208. song = s;
  209. if (song == 2) {
  210. Serial.println(" 'Underworld Theme'");
  211. int size = sizeof(underworld_melody) / sizeof(int);
  212. for (int thisNote = 0; thisNote < size; thisNote++) {
  213.  
  214. // to calculate the note duration, take one second
  215. // divided by the note type.
  216. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
  217. int noteDuration = 1000 / underworld_tempo[thisNote];
  218.  
  219. buzz(melodyPin, underworld_melody[thisNote], noteDuration);
  220.  
  221. // to distinguish the notes, set a minimum time between them.
  222. // the note's duration + 30% seems to work well:
  223. int pauseBetweenNotes = noteDuration * 1.30;
  224. delay(pauseBetweenNotes);
  225.  
  226. // stop the tone playing:
  227. buzz(melodyPin, 0, noteDuration);
  228.  
  229. }
  230.  
  231. } else {
  232.  
  233. Serial.println(" 'Mario Theme'");
  234. int size = sizeof(melody) / sizeof(int);
  235. for (int thisNote = 0; thisNote < size; thisNote++) {
  236.  
  237. // to calculate the note duration, take one second
  238. // divided by the note type.
  239. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
  240. int noteDuration = 1000 / tempo[thisNote];
  241.  
  242. buzz(melodyPin, melody[thisNote], noteDuration);
  243.  
  244. // to distinguish the notes, set a minimum time between them.
  245. // the note's duration + 30% seems to work well:
  246. int pauseBetweenNotes = noteDuration * 1.30;
  247. delay(pauseBetweenNotes);
  248.  
  249. // stop the tone playing:
  250. buzz(melodyPin, 0, noteDuration);
  251.  
  252. }
  253. }
  254. }
  255.  
  256. void buzz(int targetPin, long frequency, long length) {
  257. digitalWrite(13, HIGH);
  258. long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
  259. //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  260. //// there are two phases to each cycle
  261. long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
  262. //// multiply frequency, which is really cycles per second, by the number of seconds to
  263. //// get the total number of cycles to produce
  264. for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
  265. digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
  266. delayMicroseconds(delayValue); // wait for the calculated delay value
  267. digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
  268. delayMicroseconds(delayValue); // wait again or the calculated delay value
  269. }
  270. digitalWrite(13, LOW);
  271.  
  272. }
');