Skip to content

Commit bd31fff

Browse files
committed
Added The Godfather theme
1 parent 071e137 commit bd31fff

File tree

1 file changed

+188
-0
lines changed

1 file changed

+188
-0
lines changed

thegodfather/thegodfather.ino

+188
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
/*
2+
The Godfather
3+
Connect a piezo buzzer or speaker to pin 11 or select a new pin.
4+
More songs available at https://github.com/robsoncouto/arduino-songs
5+
6+
Robson Couto, 2019
7+
*/
8+
#define NOTE_B0 31
9+
#define NOTE_C1 33
10+
#define NOTE_CS1 35
11+
#define NOTE_D1 37
12+
#define NOTE_DS1 39
13+
#define NOTE_E1 41
14+
#define NOTE_F1 44
15+
#define NOTE_FS1 46
16+
#define NOTE_G1 49
17+
#define NOTE_GS1 52
18+
#define NOTE_A1 55
19+
#define NOTE_AS1 58
20+
#define NOTE_B1 62
21+
#define NOTE_C2 65
22+
#define NOTE_CS2 69
23+
#define NOTE_D2 73
24+
#define NOTE_DS2 78
25+
#define NOTE_E2 82
26+
#define NOTE_F2 87
27+
#define NOTE_FS2 93
28+
#define NOTE_G2 98
29+
#define NOTE_GS2 104
30+
#define NOTE_A2 110
31+
#define NOTE_AS2 117
32+
#define NOTE_B2 123
33+
#define NOTE_C3 131
34+
#define NOTE_CS3 139
35+
#define NOTE_D3 147
36+
#define NOTE_DS3 156
37+
#define NOTE_E3 165
38+
#define NOTE_F3 175
39+
#define NOTE_FS3 185
40+
#define NOTE_G3 196
41+
#define NOTE_GS3 208
42+
#define NOTE_A3 220
43+
#define NOTE_AS3 233
44+
#define NOTE_B3 247
45+
#define NOTE_C4 262
46+
#define NOTE_CS4 277
47+
#define NOTE_D4 294
48+
#define NOTE_DS4 311
49+
#define NOTE_E4 330
50+
#define NOTE_F4 349
51+
#define NOTE_FS4 370
52+
#define NOTE_G4 392
53+
#define NOTE_GS4 415
54+
#define NOTE_A4 440
55+
#define NOTE_AS4 466
56+
#define NOTE_B4 494
57+
#define NOTE_C5 523
58+
#define NOTE_CS5 554
59+
#define NOTE_D5 587
60+
#define NOTE_DS5 622
61+
#define NOTE_E5 659
62+
#define NOTE_F5 698
63+
#define NOTE_FS5 740
64+
#define NOTE_G5 784
65+
#define NOTE_GS5 831
66+
#define NOTE_A5 880
67+
#define NOTE_AS5 932
68+
#define NOTE_B5 988
69+
#define NOTE_C6 1047
70+
#define NOTE_CS6 1109
71+
#define NOTE_D6 1175
72+
#define NOTE_DS6 1245
73+
#define NOTE_E6 1319
74+
#define NOTE_F6 1397
75+
#define NOTE_FS6 1480
76+
#define NOTE_G6 1568
77+
#define NOTE_GS6 1661
78+
#define NOTE_A6 1760
79+
#define NOTE_AS6 1865
80+
#define NOTE_B6 1976
81+
#define NOTE_C7 2093
82+
#define NOTE_CS7 2217
83+
#define NOTE_D7 2349
84+
#define NOTE_DS7 2489
85+
#define NOTE_E7 2637
86+
#define NOTE_F7 2794
87+
#define NOTE_FS7 2960
88+
#define NOTE_G7 3136
89+
#define NOTE_GS7 3322
90+
#define NOTE_A7 3520
91+
#define NOTE_AS7 3729
92+
#define NOTE_B7 3951
93+
#define NOTE_C8 4186
94+
#define NOTE_CS8 4435
95+
#define NOTE_D8 4699
96+
#define NOTE_DS8 4978
97+
#define REST 0
98+
99+
100+
// change this to make the song slower or faster
101+
int tempo = 80;
102+
103+
// change this to whichever pin you want to use
104+
int buzzer = 11;
105+
106+
// notes of the moledy followed by the duration.
107+
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
108+
// !!negative numbers are used to represent dotted notes,
109+
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
110+
int melody[] = {
111+
112+
// The Godfather theme
113+
// Score available at https://musescore.com/user/35463/scores/55160
114+
115+
REST, 4, REST, 8, REST, 8, REST, 8, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, //1
116+
NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, NOTE_G4, 8,
117+
NOTE_E4, 2, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8,
118+
NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_E4, 8, NOTE_DS4, 8,
119+
120+
NOTE_D4, 2, NOTE_D4, 8, NOTE_F4, 8, NOTE_GS4, 8, //5
121+
NOTE_B4, 2, NOTE_D4, 8, NOTE_F4, 8, NOTE_GS4, 8,
122+
NOTE_A4, 2, NOTE_C4, 8, NOTE_C4, 8, NOTE_G4, 8,
123+
NOTE_F4, 8, NOTE_E4, 8, NOTE_G4, 8, NOTE_F4, 8, NOTE_F4, 8, NOTE_E4, 8, NOTE_E4, 8, NOTE_GS4, 8,
124+
125+
NOTE_A4, 2, REST,8, NOTE_A4, 8, NOTE_A4, 8, NOTE_GS4, 8, //9
126+
NOTE_G4, 2, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8,
127+
NOTE_E4, 2, NOTE_E4, 8, NOTE_G4, 8, NOTE_E4, 8,
128+
NOTE_D4, 2, NOTE_D4, 8, NOTE_D4, 8, NOTE_F4, 8, NOTE_DS4, 8,
129+
130+
NOTE_E4, 2, REST, 8, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, //13
131+
132+
//repeats from 2
133+
NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, NOTE_G4, 8, //2
134+
NOTE_E4, 2, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8,
135+
NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_E4, 8, NOTE_DS4, 8,
136+
137+
NOTE_D4, 2, NOTE_D4, 8, NOTE_F4, 8, NOTE_GS4, 8, //5
138+
NOTE_B4, 2, NOTE_D4, 8, NOTE_F4, 8, NOTE_GS4, 8,
139+
NOTE_A4, 2, NOTE_C4, 8, NOTE_C4, 8, NOTE_G4, 8,
140+
NOTE_F4, 8, NOTE_E4, 8, NOTE_G4, 8, NOTE_F4, 8, NOTE_F4, 8, NOTE_E4, 8, NOTE_E4, 8, NOTE_GS4, 8,
141+
142+
NOTE_A4, 2, REST,8, NOTE_A4, 8, NOTE_A4, 8, NOTE_GS4, 8, //9
143+
NOTE_G4, 2, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8,
144+
NOTE_E4, 2, NOTE_E4, 8, NOTE_G4, 8, NOTE_E4, 8,
145+
NOTE_D4, 2, NOTE_D4, 8, NOTE_D4, 8, NOTE_F4, 8, NOTE_DS4, 8,
146+
147+
NOTE_E4, 2 //13
148+
};
149+
150+
// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
151+
// there are two values per note (pitch and duration), so for each note there are four bytes
152+
int notes = sizeof(melody) / sizeof(melody[0]) / 2;
153+
154+
// this calculates the duration of a whole note in ms
155+
int wholenote = (60000 * 4) / tempo;
156+
157+
int divider = 0, noteDuration = 0;
158+
159+
void setup() {
160+
// iterate over the notes of the melody.
161+
// Remember, the array is twice the number of notes (notes + durations)
162+
for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
163+
164+
// calculates the duration of each note
165+
divider = melody[thisNote + 1];
166+
if (divider > 0) {
167+
// regular note, just proceed
168+
noteDuration = (wholenote) / divider;
169+
} else if (divider < 0) {
170+
// dotted notes are represented with negative durations!!
171+
noteDuration = (wholenote) / abs(divider);
172+
noteDuration *= 1.5; // increases the duration in half for dotted notes
173+
}
174+
175+
// we only play the note for 90% of the duration, leaving 10% as a pause
176+
tone(buzzer, melody[thisNote], noteDuration * 0.9);
177+
178+
// Wait for the specief duration before playing the next note.
179+
delay(noteDuration);
180+
181+
// stop the waveform generation before the next note.
182+
noTone(buzzer);
183+
}
184+
}
185+
186+
void loop() {
187+
// no need to repeat the melody.
188+
}

0 commit comments

Comments
 (0)