Advertisement
P22DX

MusicalArray.arduino

Dec 15th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Output pin */
  2. #define PIN 13
  3. /* Change to 2 for a slower version of the song, the bigger the number the slower the song */
  4. #define SPEED 1.3
  5. /* Defining note frequency */
  6. #define C4  262
  7. #define D4  294
  8. #define E4  330
  9. #define F4  349
  10. #define G4  392
  11. #define A4  440
  12. #define B4  494
  13. #define C5  523
  14. #define D5  587
  15. #define E5  659
  16. #define F5  698
  17. #define G5  784
  18. #define A5  880
  19. #define B5  988
  20. /* Note of the song, 0 is a rest/pulse */
  21. const int notes[] = {
  22.   E4, G4, A4, A4, 0,
  23.   A4, B4, C5, C5, 0,
  24.   C5, D5, B4, B4, 0,
  25.   A4, G4, A4, 0,
  26.  
  27.   E4, G4, A4, A4, 0,
  28.   A4, B4, C5, C5, 0,
  29.   C5, D5, B4, B4, 0,
  30.   A4, G4, A4, 0,
  31.  
  32.   E4, G4, A4, A4, 0,
  33.   A4, C5, D5, D5, 0,
  34.   D5, E5, F5, F5, 0,
  35.   E5, D5, E5, A4, 0,
  36.  
  37.   A4, B4, C5, C5, 0,
  38.   D5, E5, A4, 0,
  39.   A4, C5, B4, B4, 0,
  40.   C5, A4, B4, 0,
  41.  
  42.   A4, A4,
  43.   /* Repeat of first part */
  44.   A4, B4, C5, C5, 0,
  45.   C5, D5, B4, B4, 0,
  46.   A4, G4, A4, 0,
  47.  
  48.   E4, G4, A4, A4, 0,
  49.   A4, B4, C5, C5, 0,
  50.   C5, D5, B4, B4, 0,
  51.   A4, G4, A4, 0,
  52.  
  53.   E4, G4, A4, A4, 0,
  54.   A4, C5, D5, D5, 0,
  55.   D5, E5, F5, F5, 0,
  56.   E5, D5, E5, A4, 0,
  57.  
  58.   A4, B4, C5, C5, 0,
  59.   D5, E5, A4, 0,
  60.   A4, C5, B4, B4, 0,
  61.   C5, A4, B4, 0,
  62.   /* End of Repeat */
  63.  
  64.   E5, 0, 0, F5, 0, 0,
  65.   E5, E5, 0, G5, 0, E5, D5, 0, 0,
  66.   D5, 0, 0, C5, 0, 0,
  67.   B4, C5, 0, B4, 0, A4,
  68.  
  69.   E5, 0, 0, F5, 0, 0,
  70.   E5, E5, 0, G5, 0, E5, D5, 0, 0,
  71.   D5, 0, 0, C5, 0, 0,
  72.   B4, C5, 0, B4, 0, A4
  73. };
  74. /* duration of each note (in ms) Quarter Note is set to 250 ms */
  75. const int durations[] = {
  76.   125, 125, 250, 125, 125,
  77.   125, 125, 250, 125, 125,
  78.   125, 125, 250, 125, 125,
  79.   125, 125, 375, 125,
  80.  
  81.   125, 125, 250, 125, 125,
  82.   125, 125, 250, 125, 125,
  83.   125, 125, 250, 125, 125,
  84.   125, 125, 375, 125,
  85.  
  86.   125, 125, 250, 125, 125,
  87.   125, 125, 250, 125, 125,
  88.   125, 125, 250, 125, 125,
  89.   125, 125, 125, 250, 125,
  90.  
  91.   125, 125, 250, 125, 125,
  92.   250, 125, 250, 125,
  93.   125, 125, 250, 125, 125,
  94.   125, 125, 375, 375,
  95.  
  96.   250, 125,
  97.   //Rpeat of First Part
  98.   125, 125, 250, 125, 125,
  99.   125, 125, 250, 125, 125,
  100.   125, 125, 375, 125,
  101.  
  102.   125, 125, 250, 125, 125,
  103.   125, 125, 250, 125, 125,
  104.   125, 125, 250, 125, 125,
  105.   125, 125, 375, 125,
  106.  
  107.   125, 125, 250, 125, 125,
  108.   125, 125, 250, 125, 125,
  109.   125, 125, 250, 125, 125,
  110.   125, 125, 125, 250, 125,
  111.  
  112.   125, 125, 250, 125, 125,
  113.   250, 125, 250, 125,
  114.   125, 125, 250, 125, 125,
  115.   125, 125, 375, 375,
  116.   //End of Repeat
  117.  
  118.   250, 125, 375, 250, 125, 375,
  119.   125, 125, 125, 125, 125, 125, 125, 125, 375,
  120.   250, 125, 375, 250, 125, 375,
  121.   125, 125, 125, 125, 125, 500,
  122.  
  123.   250, 125, 375, 250, 125, 375,
  124.   125, 125, 125, 125, 125, 125, 125, 125, 375,
  125.   250, 125, 375, 250, 125, 375,
  126.   125, 125, 125, 125, 125, 500
  127. };
  128.  
  129. void setup() {
  130.   Serial.begin(9600);
  131.   for (int x = 0; x < 203; x++) {       /* 203 is the total number of music notes in the song */
  132.     int wait = durations[x] * SPEED;
  133.     tone(PIN, notes[x], wait);        /* tone(pin,frequency,duration) */
  134.     Serial.write("Notes : ");
  135.     Serial.println(notes[x]);
  136.     Serial.write("Times : ");
  137.     Serial.println(wait);
  138.     delay(wait);
  139.   }                        /* delay is used so it doesn't go to the next loop before tone is finished playing */
  140. }
  141.  
  142. void loop() {
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement