Open Wakype opened 2 years ago
// change this to make the song slower or faster int tempo=144;
// change this to whichever pin you want to use int buzzer = 11;
// 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[] = {
//Based on the arrangement at https://www.flutetunes.com/tunes.php?id=192
NOTE_E5, 4, NOTE_B4,8, NOTE_C5,8, NOTE_D5,4, NOTE_C5,8, NOTE_B4,8, NOTE_A4, 4, NOTE_A4,8, NOTE_C5,8, NOTE_E5,4, NOTE_D5,8, NOTE_C5,8, NOTE_B4, -4, NOTE_C5,8, NOTE_D5,4, NOTE_E5,4, NOTE_C5, 4, NOTE_A4,4, NOTE_A4,8, NOTE_A4,4, NOTE_B4,8, NOTE_C5,8,
NOTE_D5, -4, NOTE_F5,8, NOTE_A5,4, NOTE_G5,8, NOTE_F5,8, NOTE_E5, -4, NOTE_C5,8, NOTE_E5,4, NOTE_D5,8, NOTE_C5,8, NOTE_B4, 4, NOTE_B4,8, NOTE_C5,8, NOTE_D5,4, NOTE_E5,4, NOTE_C5, 4, NOTE_A4,4, NOTE_A4,4, REST, 4,
NOTE_E5, 4, NOTE_B4,8, NOTE_C5,8, NOTE_D5,4, NOTE_C5,8, NOTE_B4,8, NOTE_A4, 4, NOTE_A4,8, NOTE_C5,8, NOTE_E5,4, NOTE_D5,8, NOTE_C5,8, NOTE_B4, -4, NOTE_C5,8, NOTE_D5,4, NOTE_E5,4, NOTE_C5, 4, NOTE_A4,4, NOTE_A4,8, NOTE_A4,4, NOTE_B4,8, NOTE_C5,8,
NOTE_D5, -4, NOTE_F5,8, NOTE_A5,4, NOTE_G5,8, NOTE_F5,8, NOTE_E5, -4, NOTE_C5,8, NOTE_E5,4, NOTE_D5,8, NOTE_C5,8, NOTE_B4, 4, NOTE_B4,8, NOTE_C5,8, NOTE_D5,4, NOTE_E5,4, NOTE_C5, 4, NOTE_A4,4, NOTE_A4,4, REST, 4,
NOTE_E5,2, NOTE_C5,2, NOTE_D5,2, NOTE_B4,2, NOTE_C5,2, NOTE_A4,2, NOTE_GS4,2, NOTE_B4,4, REST,8, NOTE_E5,2, NOTE_C5,2, NOTE_D5,2, NOTE_B4,2, NOTE_C5,4, NOTE_E5,4, NOTE_A5,2, NOTE_GS5,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 (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. }
how do you do a custom song? is there any technic?
how do you do a custom song? is there any technic?
Just find the music sheet of your song and put the notes in. No technic or skill is needed 😉
can u add lil nas x song? that kinda cool i think xD