I'm Rob, an Embedded Systems Engineer, currently woking on automotive systems.
I also have worked with Industrial IoT, Smart Grids and LoRaWAN.
I enjoy learning about embedded systems, electronics and hardware hacking.
You can see a list of my personal projects at my webpage
I write at dragaosemchama.com
arduino-songs's Introduction
arduino-songs's People
Forkers
arduino-sc lmaths ankrato hardwarelayer sykesmod dinozavrix amitmamoria andreimarinescu jeanfredson decoder-majd leao1995 mcelenb sdey16 nogueira-lucas vict1860 conn0770 hackeduca carlospereira81 amylam7 gabrielbdf cemalaytekin cef3 ahmadexp tisma jabastien djotaku ezhangle gabrielgineste cableman nchristie stephensb phaoegaster rafa908 whitestorm777 thephantom8802 josielpereira afelio11 abical gdlost sspringall aiakovlev evanmputnam 4dvn undexproject victormbg chris-bena mceraso chadij yazilimtrip crisselene manthanmkulakarni asperoni-plm monocycler diasrobson sceptorrh nathant7443 st2017ho christianfreitag sagar73594 dipakmamtora nparada8 marcussacapuces91 miltonforero hasintha2002 sohamping marce240 dpenezic titowisk rogeriolimadev kotletych guiimartinho oppotop9 alessandrocanuits jackhwl mattschlosser roisinod brunoistvan gold-line hokorixiii vivianloix jurgendelaat mur38 djmoffat ramlicayan jolugama bx5974 cuba41 deathy97 williamh07 leitet molizane xploitspeeds carsonmarosi jcbender icing808 moon4ik fernandaam sarahthai maxkorlaar batugndzarduino-songs's Issues
Created Arduino-Music library based off your examples.
I created a non-blocking Arduino-Music library based off your example. Thanks for all your work here!
Ability to play mutliple songs
Hello! I love this repository and I'm looking to try and abstract a bit of it and play multiple songs from the same sketch. However, the following sketch doesnt do anything. My goal is to have various Melodies defiined above and then pass them to the play function.
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#define REST 0
// change this to whichever pin you want to use
int buzzer = D1;
// notes of the moledy followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
int cantinaMelody[] = {
// Cantina BAnd - Star wars
// Score available at https://musescore.com/user/6795541/scores/1606876
NOTE_B4,-4, NOTE_E5,-4, NOTE_B4,-4, NOTE_E5,-4,
NOTE_B4,8, NOTE_E5,-4, NOTE_B4,8, REST,8, NOTE_AS4,8, NOTE_B4,8,
NOTE_B4,8, NOTE_AS4,8, NOTE_B4,8, NOTE_A4,8, REST,8, NOTE_GS4,8, NOTE_A4,8, NOTE_G4,8,
NOTE_G4,4, NOTE_E4,-2,
NOTE_B4,-4, NOTE_E5,-4, NOTE_B4,-4, NOTE_E5,-4,
NOTE_B4,8, NOTE_E5,-4, NOTE_B4,8, REST,8, NOTE_AS4,8, NOTE_B4,8,
NOTE_A4,-4, NOTE_A4,-4, NOTE_GS4,8, NOTE_A4,-4,
NOTE_D5,8, NOTE_C5,-4, NOTE_B4,-4, NOTE_A4,-4,
NOTE_B4,-4, NOTE_E5,-4, NOTE_B4,-4, NOTE_E5,-4,
NOTE_B4,8, NOTE_E5,-4, NOTE_B4,8, REST,8, NOTE_AS4,8, NOTE_B4,8,
NOTE_D5,4, NOTE_D5,-4, NOTE_B4,8, NOTE_A4,-4,
NOTE_G4,-4, NOTE_E4,-2,
NOTE_E4, 2, NOTE_G4,2,
NOTE_B4, 2, NOTE_D5,2,
NOTE_F5, -4, NOTE_E5,-4, NOTE_AS4,8, NOTE_AS4,8, NOTE_B4,4, NOTE_G4,4,
};
void playMelody(int melody[]){
// change this to make the song slower or faster
int tempo = 140;
// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes = sizeof(melody) / sizeof(melody[0]) / 2;
// this calculates the duration of a whole note in ms
int wholenote = (60000 * 2) / tempo;
int divider = 0, noteDuration = 0;
for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
// calculates the duration of each note
divider = melody[thisNote + 1];
if (divider > 0) {
// regular note, just proceed
noteDuration = (wholenote) / divider;
} else if (divider < 0) {
// dotted notes are represented with negative durations!!
noteDuration = (wholenote) / abs(divider);
noteDuration *= 1.5; // increases the duration in half for dotted notes
}
// we only play the note for 90% of the duration, leaving 10% as a pause
tone(buzzer, melody[thisNote], noteDuration*0.9);
// Wait for the specief duration before playing the next note.
delay(noteDuration);
// stop the waveform generation before the next note.
noTone(buzzer);
}
}
void setup() {
Serial.begin(115200);
Serial.println("Play stuff");
// iterate over the notes of the melody.
// Remember, the array is twice the number of notes (notes + durations)
playMelody(cantinaMelody);
}
void loop() {
// no need to repeat the melody.
}
If I change the following to use catinaMelody
from global rather than the melody
I pass it from the function, but that defeats the purpose. Am I missing something basic?
// change this to make the song slower or faster
int tempo = 140;
// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes = sizeof(melody) / sizeof(melody[0]) / 2;
// this calculates the duration of a whole note in ms
int wholenote = (60000 * 2) / tempo;
Add Megalovania(Undertale theme) *Look in comment for code*
CODE
// Megalovania, Toby Fox
// Notes at https://pianoletternotes.blogspot.com/2017/10/megalovania-undertale-theme.html
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#define REST 0
// change this to make the song slower or faster
int tempo=150;
// change this to whichever pin you want to use
int buzzer = 11;
// notes of the melody followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
int melody[] = {
NOTE_D4, 12, NOTE_D4, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_C4, 12, NOTE_C4, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_B3, 12, NOTE_B3, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_AS3, 8, NOTE_AS3, 8, NOTE_D5, 12, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_D4, 12, NOTE_D4, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_C4, 12, NOTE_C4, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_B3, 12, NOTE_B3, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_AS3, 8, NOTE_AS3, 8, NOTE_D5, 12, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_D4, 12, NOTE_D4, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_C4, 12, NOTE_C4, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_B3, 12, NOTE_B3, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_AS3, 8, NOTE_AS3, 8, NOTE_D5, 12, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_D4, 12, NOTE_D4, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_C4, 12, NOTE_C4, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_B3, 12, NOTE_B3, 12, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_AS3, 8, NOTE_AS3, 8, NOTE_D5, 12, REST, 16, NOTE_A4, 8,
REST, 12,
NOTE_GS4, 8, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 8, REST, 20, NOTE_D4, 16, NOTE_F4, 16, NOTE_G4, 12,
NOTE_F4, 16, REST, 12, NOTE_F4, 12, NOTE_F4, 12, REST, 16, NOTE_F4, 12, REST, 16, NOTE_F4, 12, REST, 16, NOTE_D4, 12,
REST, 16,
NOTE_D4, 12, REST, 12, NOTE_D4, 4, REST, 16, NOTE_F4, 12, NOTE_F4, 12, NOTE_F4, 12, NOTE_F4, 12, REST, 16, NOTE_G4, 16,
NOTE_GS4, 12, REST, 16, NOTE_G4, 12, NOTE_F4, 8, NOTE_D4, 12, NOTE_F4, 12, NOTE_G4, 8,
NOTE_F4, 12, REST, 16, NOTE_F4, 12, NOTE_F4, 12, REST, 16,
NOTE_G4, 12, NOTE_GS4, 8,
REST, 16, NOTE_A4, 12, REST, 16, NOTE_C5, 12, REST, 12, NOTE_A4, 12, REST, 12, NOTE_D5, 12, REST, 16, NOTE_D5, 12,
REST, 16, NOTE_D5, 12, NOTE_A4, 12, NOTE_D5, 12, NOTE_C5, 4,
REST, 2,
NOTE_A4, 12, REST, 16, NOTE_A4, 12, NOTE_A4, 12, REST, 16, NOTE_A4, 12, REST, 16,
NOTE_A4, 12, REST, 16, NOTE_G4, 12, REST, 16, NOTE_G4, 12, REST, 4, NOTE_A4, 12, REST, 16, NOTE_A4, 12, NOTE_A4, 12,
REST, 16, NOTE_A4, 12, REST, 16, NOTE_G4, 12, REST, 16,
NOTE_A4, 12, REST, 16, NOTE_D5, 12, REST, 16, NOTE_A4, 12, REST, 16, NOTE_G4, 12, REST, 16, NOTE_D5, 12, REST, 16,
NOTE_A4, 12, REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 12, REST, 16, NOTE_C5, 12, REST, 16, NOTE_A4, 12,
REST, 16, NOTE_G4, 12, REST, 16, NOTE_F4, 12, REST, 16, NOTE_D4, 12, REST, 16, NOTE_E4, 12, NOTE_F4, 12, REST, 16,
NOTE_A4, 12, REST, 16, NOTE_C5, 12,
REST, 2,
NOTE_F4, 12, NOTE_D4, 12, NOTE_F4, 12, NOTE_G4, 12, NOTE_GS4, 12, NOTE_G4, 12, NOTE_F4, 12, NOTE_D4, 12, NOTE_GS4, 12,
NOTE_G4, 12, NOTE_F4, 12, NOTE_D4, 12, NOTE_F4, 12, NOTE_G4, 12,
REST, 2,
NOTE_GS4, 12, REST, 16, NOTE_A4, 12, NOTE_C4, 12, REST, 16, NOTE_A4, 12, NOTE_GS4, 12, NOTE_G4, 12, NOTE_F4, 12,
NOTE_D4, 12, NOTE_F4, 12, REST, 16, NOTE_G4, 12, NOTE_GS4, 12, REST, 16, NOTE_C5, 12, REST, 12, NOTE_CS5, 12, REST, 16,
NOTE_GS4, 12, REST, 16, NOTE_GS4, 12, NOTE_G4, 12, NOTE_F4, 12, NOTE_G4, 12,
REST, 2,
NOTE_F3, 12, REST, 16, NOTE_G3, 12, REST, 16, NOTE_A3, 12, REST, 16, NOTE_F4, 12, REST, 16, NOTE_E4, 10, REST, 16,
NOTE_D4, 10, REST, 16, NOTE_E4, 10, REST, 16, NOTE_F4, 10, REST, 16, NOTE_G4, 10, REST, 16, NOTE_E4, 10,
NOTE_A4, 4,
REST, 2,
NOTE_A4, 12, NOTE_GS4, 12, NOTE_G4, 12, NOTE_FS4, 12, NOTE_F4, 12, NOTE_E4, 12, NOTE_DS4, 12, NOTE_D4, 12,
NOTE_CS4, 8, REST, 8, NOTE_DS4, 8,
REST, 2,
NOTE_F4, 12, NOTE_D4, 12, NOTE_F4, 12, NOTE_G4, 12, NOTE_GS4, 12, NOTE_G4, 12, NOTE_F4, 12, NOTE_D4, 12, NOTE_GS4, 12,
NOTE_G4, 12, NOTE_F4, 12, NOTE_D4, 12, NOTE_F4, 12, NOTE_G4, 12,
REST, 2,
NOTE_GS4, 12, REST, 16, NOTE_A4, 12, NOTE_C4, 12, REST, 16, NOTE_A4, 12, NOTE_GS4, 12, NOTE_G4, 12, NOTE_F4, 12,
NOTE_D4, 12, NOTE_F4, 12, REST, 16, NOTE_G4, 12, NOTE_GS4, 12, REST, 16, NOTE_C5, 12, REST, 12, NOTE_CS5, 12, REST, 16,
NOTE_GS4, 12, REST, 16, NOTE_GS4, 12, NOTE_G4, 12, NOTE_F4, 12, NOTE_G4, 12,
REST, 2,
NOTE_F3, 12, REST, 16, NOTE_G3, 12, REST, 16, NOTE_A3, 12, REST, 16, NOTE_F4, 12, REST, 16, NOTE_E4, 10, REST, 16,
NOTE_D4, 10, REST, 16, NOTE_E4, 10, REST, 16, NOTE_F4, 10, REST, 16, NOTE_G4, 10, REST, 16, NOTE_E4, 10,
NOTE_A4, 4,
REST, 2,
NOTE_A4, 12, NOTE_GS4, 12, NOTE_G4, 12, NOTE_FS4, 12, NOTE_F4, 12, NOTE_E4, 12, NOTE_DS4, 12, NOTE_D4, 12,
NOTE_CS4, 8, REST, 8
};
// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes=sizeof(melody)/sizeof(melody[0])/2;
// this calculates the duration of a whole note in ms (60s/tempo)*4 beats
int wholenote = (60000 * 4) / tempo;
int divider = 0, noteDuration = 0;
void setup() {
// iterate over the notes of the melody.
// Remember, the array is twice the number of notes (notes + durations)
for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
// calculates the duration of each note
divider = melody[thisNote + 1];
if (divider > 0) {
// regular note, just proceed
noteDuration = (wholenote) / divider;
} else if (divider < 0) {
// dotted notes are represented with negative durations!!
noteDuration = (wholenote) / abs(divider);
noteDuration *= 1.5; // increases the duration in half for dotted notes
}
// we only play the note for 90% of the duration, leaving 10% as a pause
tone(buzzer, melody[thisNote], noteDuration*0.9);
// Wait for the specief duration before playing the next note.
delay(noteDuration);
// stop the waveform generation before the next note.
noTone(buzzer);
}
}
void loop() {
// no need to repeat the melody.
}
Info
- Megalovania by Toby Fox
- Notes at https://pianoletternotes.blogspot.com/2017/10/megalovania-undertale-theme.html
So great thank you
NOTE_C2,4, NOTE_G2,3, NOTE_C3,8, NOTE_AS2,3, NOTE_A2,16 ,NOTE_G2,16, NOTE_A2,4, NOTE_G2,8, NOTE_F2,8, NOTE_G2,2, NOTE_G2,16, NOTE_G2,16, NOTE_G2,16,
Back to the future first notes ;-) ;-)
Non-Blocking Code
Amazing work! Kudos!
I made some changes to your code to make it non-blocking: instead of delay statements for each note and program logic waiting for the song to end, my changes allow for program execution while the tunes are being played.
Also I added a flag that can stop tune playback before it ends (for example if program logic requires it).
I also added the option to have up to 10 tunes selectable either by user input or by program logic.
Thanks!
Note: I don't know how to upload programs into a reported issue other than presenting the full code using markup language, so I renamed the NonBlockingTunes.INO and the tunes.h files to .TXT so that they could be copied here.
The Godfather theme not according to sheet. Wrong note.
The first section is currently:
REST, 4, REST, 8, REST, 8, REST, 8, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, //1 NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, NOTE_G4, 8, NOTE_E4, 2, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_E4, 8, NOTE_DS4, 8,
And it should be:
REST, 4, REST, 8, REST, 8, REST, 8, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, //1 NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_F4, 8, NOTE_G4, 8, NOTE_E4, 2, NOTE_E4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_C5, 8, NOTE_A4, 8, NOTE_B4, 8, NOTE_A4, 8, NOTE_E4, 8, NOTE_DS4, 8,
It sounded off and I just checked with the music sheet and the original song.
Please do Jurassic Park theme.
Highly supported
Any possibility to turn speak off during rest notes
Hey guys great work but I was wondering if it's possible to program it the way that rest notes are just rest notes and not the basic tone of the speaker.
can you make jurassic park theme please?
Can you add Transformers G1 transition sound effect please i need it for a project
This nice music on ESP32
Great work at first.
Looked for music I can use on my ESP32 with the Tone32.h library. This here works well till the first note with a "-".
Then I removed it and now the code works.
I made from
"NOTE_D5, -4,"
"NOTE_D5, 4,"
Now he play the song.
Just a thank you!
Thank you mate. I like your songs! I'm using "Pulo da Gaita" for my small project. Thanks again!
Esp32?
Hello, can those songs be used on esp32 somehow? Tone/ noTone doesn't seem to work, maybe I messed something up with libraries.
How can I contribute to this repo?
I used you code as an example to translate scores into sketch.
So far I've got only Ride of the Valkyries, but I plan to translate few more for my project soon.
It would be nice if I could add those melodies to this repo for others to use, but I don't have access.
Attached is a code for your reference, feel free to use it.
rideofthevalkyries.txt
add im blue
Im_Blue_by_Eiffel_65_for_Piano.zip
here is a midi file
its compressed to a zip file
Could you make reach for the stars? (The one from sonic colors)
btw I was looking for Never Gonna give you up on arduino, thx!
Tetris is wrong
lines 117 and 127 should be "NOTE_C5, 4, NOTE_A4,4, NOTE_A4,4, NOTE_B4,8, NOTE_C5,8,"
you added an extra eighth note in the sequence
Pac Man theme
Hi, I love your repo, it trully rocks ! Do you intend to implement PacMan theme ?
I'll use your work in a fun DIY project, I'l quote you.
Have a nice day.
Kind Regards,
Adrien
New_song_generation
HI, I really like your repo, can you provide further details about how can we start doing it on our own for any other songs? that will be really helpful to everyone.
Arduino songs with a button
I wanted to play a song using a button but I have no idea how to do it
podrian hacer una de caballeros del zodiaco la saga de ades?
podrian hacer una de caballeros del zodiaco la saga de ades?
Generator for songs
Hi this is perfect code. Is some generator for songs?
Songs are unlicensed
I was hoping to use this song data in an open source project also hosted here on Github, with lots of attribution etc. However at present the code is not licensed with an open source license (or indeed with any license). The author helpfully states "You can use the sketches for anything, I only kindly ask that you give credit if you use these codes on a tutorial, video, example, etc.", but this isn't sufficient to include code in an open source licensed project.
May I suggest that the author perhaps license the code as MIT or (better yet) Apache 2.0? It'd help a lot.
Arduino Songs
Buttons don't work while buzzer is playing
Hi!
Firstly, I loved the songs. And thank you for your work!
Secondly, I'm building a little game with an arduino mega 2560. It's really simple. 2 People will battle to see who has the faster finger press (Basically they'll define the number of button press and see who presses faster).
Basically, I have 5 buttons (2 arcade and 3 simple push buttons), 1 LCD i2C 16,2 screen, 1 4Digit 7 segment display and a buzzer.
On my code (I haven't finished it yet) I was trying to test the functionalities (pressing any of the buttons while the buzzer is playing) I implemented so far, and the buttons stopped working while the music was playing.
If I comment the function that makes the music play and re-upload to my arduino, all of the buttons work again.
I don't know why this is happening. I was hopping to play 3 musics. 1. while the player are setting up the game (defining the number of presses etc), 2. while the game is running (while the are pressing the buttons) and 3. when someone wins.
If anyone could help me, I would be really grateful.
Anyway, thank you!
EDIT: I tried putting the Music() function on the setup(), and the buttons still didn't work while the song was playing. After it ended the buttons work normally. Don't know why. (Welcome to programming I guess?)
(I'll post the code here!)
(I've divided the code into 2 tabs. The main one has almost everything. The second one just has the Music() function).
(FYI, I'm brazilian. So some parts of the code has a comment or two in portuguese. :/ ).
//////////////////
//CODE ONE//
//////////////////
// Libraries
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define cada nota para um frequencia em hertz
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#define REST 0
// change this to make the song slower or faster
int tempo = 108; // 108 is standard.
// change this to whichever pin you want to use
int buzzer = 27;
// notes of the moledy followed by the duration.
// a 4 means a quarter note, 8 an eighteenth , 16 sixteenth, so on
// !!negative numbers are used to represent dotted notes,
// so -4 means a dotted quarter note, that is, a quarter plus an eighteenth!!
int melody[] = {
NOTE_E4,2, NOTE_G4,4,
NOTE_D4,2, NOTE_C4,8, NOTE_D4,8,
NOTE_E4,2, NOTE_G4,4,
NOTE_D4,-2,
NOTE_E4,2, NOTE_G4,4,
NOTE_D5,2, NOTE_C5,4,
NOTE_G4,2, NOTE_F4,8, NOTE_E4,8,
NOTE_D4,-2,
NOTE_E4,2, NOTE_G4,4,
NOTE_D4,2, NOTE_C4,8, NOTE_D4,8,
NOTE_E4,2, NOTE_G4,4,
NOTE_D4,-2,
NOTE_E4,2, NOTE_G4,4,
NOTE_D5,2, NOTE_C5,4,
NOTE_G4,2, NOTE_F4,8, NOTE_E4,8,
NOTE_F4,8, NOTE_E4,8, NOTE_C4,2,
NOTE_F4,2, NOTE_E4,8, NOTE_D4,8,
NOTE_E4,8, NOTE_D4,8, NOTE_A3,2,
NOTE_G4,2, NOTE_F4,8, NOTE_E4,8,
NOTE_F4,8, NOTE_E4,8, NOTE_C4,4, NOTE_F4,4,
NOTE_C5,-2,
};
// sizeof gives the number of bytes, each int value is composed of two bytes (16 bits)
// there are two values per note (pitch and duration), so for each note there are four bytes
int notes = sizeof(melody) / sizeof(melody[0]) / 2;
// this calculates the duration of a whole note in ms
int wholenote = (60000 * 4) / tempo;
int divider = 0, noteDuration = 0;
// Seta o adress da LCD para 0x3F para 16 chars e 2 linhas do display
LiquidCrystal_I2C lcd(0x3F, 16, 2);
// Definindo as variaveis
// Botoes
int numberButtons = 5; // Numero total de botoes
int startPin = 22; // Onde comeca a porta dos botoes
int buttons[5]; // Lista com todos os botoes
boolean buttonsBool[5]; // Bool pra checar o estado do botao
// Buzzer
const int miniSom = 27; // Pin do MiniSom
// Jogo
int pressNumber = 0; // Numero total de vezes que vao ser apertadas no jogo
void setup() {
Serial.begin(9600);
// Inicilizando todos os botoes em seus respectivos pins
for (int i = 0; i < numberButtons; i++)
buttons[i] = i + startPin;
// Setando todos os botoes para o estado de falso
for (int i = 0; i < numberButtons; i++)
buttonsBool[i] = false;
// Setando todos os botoes para o estado de input pullup
for (int i = 0; i < numberButtons; i++)
pinMode(buttons[i], INPUT_PULLUP);
pinMode(miniSom, OUTPUT);
// inicializando o lcd
lcd.init();
// Liga a luz de fundo e limpa a tela com o clear
lcd.backlight();
lcd.clear();
}
void loop() {
//Music();
ButtonPressing();
/*
digitalWrite(miniSom, HIGH);
delay(1000);
digitalWrite(miniSom, LOW);
delay(1000);
*/
}
void ButtonPressing() {
// while (digitalRead(buttons[2] == HIGH))
// {
for (int i = 0; i < numberButtons; i++) {
if (!buttonsBool[i]) {
if (digitalRead(buttons[i]) == LOW) {
if (i == 0) {
pressNumber++;
lcd.clear();
lcd.print(pressNumber);
buttonsBool[i] = true;
} else if (i == 1) {
pressNumber += 10;
lcd.clear();
lcd.print(pressNumber);
buttonsBool[i] = true;
} else if (i == 2) {
lcd.clear();
pressNumber = 0;
} else if (i == 3) {
lcd.clear();
lcd.print("Player 1 funcionando!");
buttonsBool[i] = true;
} else if (i == 4) {
lcd.clear();
lcd.print("Player 2 funcionando!");
buttonsBool[i] = true;
}
}
} else {
if (digitalRead(buttons[i]) == HIGH) {
buttonsBool[i] = false;
}
}
}
delay(15);
}
//////////////////
//CODE TWO//
//////////////////
void Music(){
// iterate over the notes of the melody.
// Remember, the array is twice the number of notes (notes + durations)
for (int thisNote = 0; thisNote < notes * 2; thisNote = thisNote + 2) {
// calculates the duration of each note
divider = melody[thisNote + 1];
if (divider > 0) {
// regular note, just proceed
noteDuration = (wholenote) / divider;
} else if (divider < 0) {
// dotted notes are represented with negative durations!!
noteDuration = (wholenote) / abs(divider);
noteDuration *= 1.5; // increases the duration in half for dotted notes
}
// we only play the note for 90% of the duration, leaving 10% as a pause
tone(buzzer, melody[thisNote], noteDuration*0.9);
// Wait for the specief duration before playing the next note.
delay(noteDuration);
// stop the waveform generation before the next note.
noTone(buzzer);
}
}
add another song :)
can u add lil nas x song? that kinda cool i think xD
can you do among us drip
Iโm just gonna do it to my friends Iโm not obsessed with among us
could you please code Treachery by Shiro Sagisu?
link to the song: https://www.youtube.com/watch?v=0kYq-E8BJgU
can any of these be used on the smart inventor-mega32_v2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.