-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmusicxml_to_arduino.ino
35 lines (25 loc) · 6.04 KB
/
musicxml_to_arduino.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
Play melody
*/
#include "pitches.h"
int notes[] = {NOTE_CS5,NOTE_B4,NOTE_D5,NOTE_CS5,NOTE_B4,NOTE_A4,NOTE_B4,NOTE_CS5,NOTE_CS5,NOTE_CS5,NOTE_A5,NOTE_A5,NOTE_GS5,NOTE_GS5,NOTE_FS5,NOTE_FS5,NOTE_CS5,NOTE_B4,NOTE_D5,NOTE_CS5,NOTE_B4,NOTE_A4,NOTE_B4,NOTE_CS5,NOTE_CS5,NOTE_B4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_CS5,NOTE_B4,NOTE_B4,NOTE_B4,NOTE_CS5,NOTE_B4,NOTE_B4,NOTE_B4,NOTE_CS5,NOTE_A4,NOTE_B4,NOTE_B4,NOTE_GS4,NOTE_A4,NOTE_B4,NOTE_B4,NOTE_GS4,NOTE_A4,NOTE_GS4,NOTE_FS4,NOTE_CS5,NOTE_B4,NOTE_B4,NOTE_A4,NOTE_GS4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_GS4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_B4,NOTE_A4,NOTE_GS4,NOTE_GS4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_CS4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_FS4,NOTE_FS4,NOTE_CS4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_CS4,NOTE_CS4,NOTE_CS4,NOTE_B3,NOTE_A3,NOTE_B3,NOTE_B3,NOTE_B3,NOTE_B3,NOTE_B3,NOTE_B3,NOTE_CS4,NO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OTE_B4,NOTE_B4,NOTE_GS4,NOTE_A4,NOTE_GS4,NOTE_FS4,NOTE_CS5,NOTE_B4,NOTE_B4,NOTE_A4,NOTE_GS4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_GS4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_B4,NOTE_A4,NOTE_GS4,NOTE_GS4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_GS5,NOTE_FS5,NOTE_FS5,NOTE_CS5,NOTE_B4,NOTE_A4,NOTE_B4,NOTE_CS5,NOTE_CS5,NOTE_CS5,NOTE_FS4,NOTE_FS4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_E4,NOTE_FS4,NOTE_FS4,NOTE_B4,NOTE_A4,NOTE_GS4,NOTE_GS4,NOTE_A4,NOTE_A4,NOTE_A4,NOTE_A4,};
int durations[] = {1500.0,500.0,1500.0,125.0,250.0,125.0,375.0,125.0,500.0,375.0,125.0,375.0,125.0,375.0,125.0,1500.0,1500.0,500.0,1500.0,125.0,250.0,125.0,375.0,125.0,1000.0,500.0,750.0,250.0,1000.0,500.0,250.0,250.0,500.0,500.0,250.0,250.0,500.0,500.0,375.0,125.0,250.0,250.0,375.0,125.0,250.0,250.0,125.0,125.0,750.0,375.0,125.0,250.0,250.0,375.0,125.0,250.0,250.0,1000.0,375.0,125.0,250.0,250.0,500.0,125.0,250.0,125.0,375.0,125.0,250.0,250.0,1000.0,250.0,125.0,125.0,125.0,250.0,125.0,250.0,250.0,500.0,125.0,250.0,125.0,125.0,125.0,250.0,125.0,250.0,250.0,500.0,1000.0,125.0,250.0,125.0,250.0,125.0,125.0,125.0,125.0,250.0,250.0,250.0,250.0,125.0,125.0,125.0,125.0,250.0,250.0,125.0,250.0,125.0,375.0,125.0,250.0,250.0,1000.0,250.0,125.0,125.0,125.0,125.0,250.0,250.0,500.0,250.0,125.0,250.0,125.0,125.0,125.0,250.0,125.0,250.0,250.0,1500.0,250.0,125.0,125.0,125.0,125.0,250.0,250.0,250.0,250.0,125.0,125.0,125.0,125.0,250.0,125.0,250.0,125.0,375.0,125.0,250.0,250.0,1000.0,375.0,125.0,250.0,250.0,375.0,125.0,250.0,250.0,750.0,125.0,125.0,500.0,375.0,125.0,250.0,250.0,375.0,125.0,250.0,250.0,1000.0,375.0,125.0,250.0,250.0,250.0,500.0,250.0,375.0,125.0,250.0,250.0,1000.0,375.0,125.0,250.0,250.0,1000.0,375.0,125.0,250.0,250.0,250.0,500.0,250.0,375.0,125.0,250.0,250.0,500.0,500.0,2000.0,500.0,250.0,250.0,500.0,500.0,250.0,250.0,500.0,500.0,375.0,125.0,250.0,250.0,375.0,125.0,250.0,250.0,125.0,125.0,750.0,375.0,125.0,250.0,250.0,375.0,125.0,250.0,250.0,1000.0,375.0,125.0,250.0,250.0,500.0,125.0,250.0,125.0,375.0,125.0,250.0,250.0,1000.0,375.0,125.0,500.0,125.0,250.0,125.0,375.0,125.0,500.0,250.0,250.0,500.0,375.0,125.0,250.0,250.0,250.0,250.0,500.0,125.0,250.0,125.0,375.0,125.0,250.0,250.0,1000.0,};
int delays[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,375.0,375.0,375.0,375.0,375.0,375.0,375.0,375.0,375.0,375.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,250.0,250.0,250.0,250.0,250.0,250.0,250.0,250.0,250.0,250.0,250.0,250.0,250.0,250.0,250.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,375.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,1000.0,1000.0,1000.0,1000.0,1000.0,1000.0,1000.0,1000.0,1000.0,1000.0,1000.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,2000.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,500.0,1000.0,1000.0,1000.0,1000.0,1000.0,1000.0,1000.0,1000.0,};
int melody_size = 279;
void setup() {
}
void loop() {
for (int thisNote = 0; thisNote < melody_size + 1; thisNote++) {
int noteDuration = durations[thisNote];
tone(8, notes[thisNote],noteDuration);
int pauseBetweenNotes;
if(delays[thisNote] == 0) {
pauseBetweenNotes = noteDuration;
} else {
pauseBetweenNotes = delays[thisNote];
}
delay(pauseBetweenNotes);
noTone(8);
}
delay (100);
}