Code For Arduino Programming Mary Had A Little Lamb
Code For Arduino Programming Mary Had A Little Lamb
char notes[] = "bagaHbbb Haaa HbDD JbagaHbbb KbaaLbag MbagaNbbb Naaa NbDD
MbagaNbbb ObaaPbag DQbagaRbbb Raaa RbDD QbagaRbbb SbaabTag DUbagaVbbb Vaaa
VbDD UbagaVbbb WbaabXag Y";
// The notes in the song, on a treble clef scale.
// A space represents a rest, and capital letters H through X are used to initialize lyrics that
correlate to a certain portion of the song.
// The lowercase letters a through g represent notes, with set frequencies later in the code.
int beats[] =
{2,2,2,2,0,2,2,4,1,0,2,2,4,1,0,2,2,4,1,0,2,2,2,2,0,2,2,4,1,0,2,2,2,0,2,2,4,1,0,2,2,2,2,0,2,2,4,1,0,2,
2,4,1,0,2,2,4,1,0,2,2,2,2,0,2,2,4,1,0,2,2,2,0,2,2,4,1,2,0,2,2,2,2,0,2,2,4,1,0,2,2,4,1,0,2,2,4,1,0,2,2,
2,2,0,2,2,4,1,0,2,2,2,2,0,2,4,1,2,0,2,2,2,2,0,2,2,4,1,0,2,2,4,1,0,2,2,4,1,0,2,2,2,2,0,2,2,4,1,0,2,2,2,
2,0,2,4,1,0,};
int tempo = 150; // The tempo is a command of how fast to play the song, in beats per second.
(In this case, the tempo is 150 beats per second)
void setup() // This will setup the functions necessary for the code to work, suchh as initializing
the LCD and buzzer.
{
pinMode(buzzerPin, OUTPUT); // Configures the buzzer pin, and makes it into an output instead
of an input.
pinMode (13, OUTPUT) ;// Connect the LED to pin 13, and configues it as an output instead of
an input
lcd.begin(16, 2); //Initialize the 16x2 LCD
void loop() // This will run the following functions over and over again.
{
int i, duration; // Labeling the integer as "i."
for (i = 0; i < songLength; i++) // This function is used to index through the arrays
{
duration = beats[i] * tempo; // Length of note/rest in milliseconds
while(true){ // This function makes the song only play once, by pausing forever.
}
}