#include "pitches.h"
int buzzerpin = 8;
#define NUMNOTES 15 // the number of notes in the song, includint the lase silent note.
const int notes[NUMNOTES] = {
NOTE_C4, NOTE_C4, NOTE_G4, NOTE_G4, //The musical notes in sequence but without the timing-tempo
NOTE_A4, NOTE_A4, NOTE_G4, NOTE_F4,
NOTE_F4, NOTE_E4, NOTE_E4, NOTE_D4,
NOTE_D4, NOTE_C4, 0
};
const int beats[NUMNOTES] = {
1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 }; //the timing of the notes
const int beat_length = 300;
void setup()
{
pinMode(buzzerpin, OUTPUT); //telling the Arduino that buzzerpin (pin 8) will be an output pin
}
void ourTone(int freq, int duration)
{
tone(buzzerpin, freq, duration); //play a note(which pin, what note, what duration)
delay(duration); // Puase for a set time
}
void loop()
{
for (int i = 0; i < NUMNOTES; i++) { //creates a loop starting at 0 and adding 1 each time the loop completes
if (notes[i] == 0) { //it will repeat the loop until i is greater than 15 (the number of notes)
delay(beats[i] * beat_length); // rest
}
else {
ourTone(notes[i], beats[i] * beat_length);
}
// pause between notes
noTone(buzzerpin);
delay(beat_length / 2);
}
}