#include "pitches.h"
int speakerPin = 8;
int happy_birthday[] = {
NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_C5, NOTE_B4, ' ',
NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_D5, NOTE_C5, ' ',
NOTE_G4, NOTE_G4, NOTE_G5, NOTE_E5, NOTE_C5, NOTE_B4, NOTE_A4, ' ',
NOTE_F5, NOTE_F5, NOTE_E5, NOTE_C5, NOTE_D5, NOTE_C5
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
1,1,2,2,2,2,2,1,1,2,2,2,2,2,1,1,2,2,2,2,2,1,1,2,2,2,2,2,2
};
int length = sizeof(happy_birthday);
int tempo = 1500;
void setup() {
pinMode(speakerPin, OUTPUT);
}
void playNote(int OutputPin, int songs[], int noteDurations[]){
for (int i = 0; i < length; i++){
if (songs[i] == ' '){
delay(noteDurations[i] * tempo * 0.5);
}else{
tone(OutputPin, songs[i], noteDurations[i] * tempo);
delay(tempo/5);
noTone(OutputPin);
}
}
}
void loop() {
playNote(speakerPin, happy_birthday, noteDurations);
}