// The Arduino Mega 2560 has a total of 3 timers, only 2 of which can be used to
// play a tone, the 3rd must beused for delay and other clock functions on the board
#include "Multi_Tone.h" // this is needed to gain access to the additional clocks
#define BUZZER1 8 // defines the pin number for the first buzzer
#define BUZZER2 9 // defines the pin number for the second buzzer
Tone freq1; // sets up the clock for the first buzzer
Tone freq2; // sets up the clock for the second buzzer
int melody[] = {NOTE_E4, NOTE_D4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_D4,
NOTE_D4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_G4, NOTE_G4, NOTE_G4, NOTE_E4, NOTE_D4,
NOTE_C4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_D4, NOTE_D4, NOTE_E4,
NOTE_D4, NOTE_C4, NOTE_C4, NOTE_C4, NOTE_C4, }; // the melody line of the music
int harmony[] = {NOTE_C3, NOTE_C3, NOTE_G3, NOTE_G3, NOTE_C3, NOTE_C3, NOTE_G3, NOTE_G3, NOTE_G3,
NOTE_G3, NOTE_B3, NOTE_B3, NOTE_C3, NOTE_C3, NOTE_G3, NOTE_G3, NOTE_C3, NOTE_C3,
NOTE_G3, NOTE_G3, NOTE_C3, NOTE_C3, NOTE_G3, NOTE_G3, NOTE_G3, NOTE_G3, NOTE_B3,
NOTE_B3, NOTE_C3, NOTE_C3, NOTE_C3, NOTE_C3,}; // the harmony line of the music
// this sets how long each beat sounds for, all of the tone are played for the same base length
// of time, to change the lenth of the note, more of the same tone are played, modifying this
// changes how fast the song is played
int beat = 250;
void setup()
{
freq1.begin(BUZZER1); // sets up the buzzer to be used with the Multi_Tone library
freq2.begin(BUZZER2); // sets up the buzzer to be used with the Multi_Tone library
for (int count = 0; count < 32; count++) //loops through all of the beats in the song
{
freq1.play(melody[count]); // plays the melody note based on the count variable from the for loop
freq2.play(harmony[count]); // plays the corisponding harmony note
delay(beat); //pauses the code to play the tone for the desired length
}
freq1.stop(); // turns off the first buzzer DO NOT USE freq#.play(0)
freq2.stop(); // turns off the second buzzer DO NOT USE freq#.play(0)
}
void loop()
{freq1.play(65535);
}