Вы находитесь на странице: 1из 3

John Cena fo REAL

By: Sean Burke and Chris Griggy

const int buzzerPin = 9; //Send infortmation for buzzer to digital pin 9

const int songLength = 33; //The song is 33 notes including pauses

char notes[] = "agfd gfed Gaf g Caf g gaf g Caf g"; //These notes are different frequencies, each
space represents a rest

int beats[] = {16, 16, 16, 16, 3, 16, 16, 16, 16, 4, 4, 2, 2, 1, 8, 6, 4, 2, 2, 1, 8, 6, 4, 2, 2, 1, 8, 6, 4,
2, 2, 1, 8};
//These are how long each note lasts.

int tempo = 75; //How fast the song goes


#include <LiquidCrystal.h> //Include the LCD

LiquidCrystal lcd(12,11,5,4,3,2);
//Use these digital pins.

void setup() // Settings for the beginning of the show


{
pinMode(buzzerPin, OUTPUT);//send signal to buzzer

lcd.begin(16, 2);//

lcd.clear();//Clear the LCD

lcd.print("And his name is");//Self explanatory

void loop() //The things loop


{
int i, duration;// For the duration of the song, do the following

for (i = 0; i < songLength; i++) //The song goes up one beat at a time.
{
duration = beats[i] * tempo; // length of note/rest in ms

if (notes[i] == ' ') // is this a rest?


{
delay(duration); // then pause for a moment
}
if (notes[i] == 'G') // If this note shows up, then do the following
{
lcd.setCursor(0,1); // Where the text will start
lcd.print("John Cena!!!!!"); // Show the print on the LCD
tone(buzzerPin, frequency(notes[i]), duration);
delay(duration); // wait for tone to finish

delay(tempo/10); } // Brief pause between notes


else // otherwise, play the note
{
tone(buzzerPin, frequency(notes[i]), duration); // play a note
delay(duration); // wait for tone to finish
}
delay(tempo/10); // brief pause between notes
}
}

int frequency(char note)


{
//Associate a frequency with a note

int i;
const int numNotes = 9; // number of notes

//Each note is given a frequency for the buzzer.

char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'G' };
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523, 392};

for (i = 0; i < numNotes; i++) //go 1by1 through the notes.


{
if (names[i] == note) // If there is a note
{
return(frequencies[i]); // Return the frequency
}
}
return(0); // If there are no notes, just return 0
}

Вам также может понравиться