Evidence of Work
Those are a picture and video of our project in action!
Circuit Diagram
This is our circuit diagram. Its pretty self explanatory. It shows what wires are connected to what. From a physical standpoint.
Code
Thomas and Brett’s Code
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int speakerPin = 9;
int length = 28; // the number of notes
char notes[] = "GGAGcB GGAGdc GGxecBA yyecdc";
int beats[] = { 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8,8, 16, 1, 2,2,8,8,8,8,16, 1,2,2,8,8,8,16 };
String lyric1[] = {"Ha ", "Happy", "Happy Birth", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Ha ", "Happy", "Happy Birth", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Ha ", "Happy", "Happy Birth", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Ha ", "Happy", "Happy Birth", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday"};
String lyric2[] = {" ", "", "", "", "To", "To You", "To You", " ", "", "", "", "To", "To You", "To You", " ", "", "", "", "Dear", "Dear Bret", "Dear Bretton", " ", "", "", "", "To", "To You", "To You"};
int tempo = 150;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B',
'c', 'd', 'e', 'f', 'g', 'a', 'b',
'x', 'y' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014,
956, 834, 765, 593, 468, 346, 224,
655 , 715 };
int SPEE = 5;
// play the tone corresponding to the note name
for (int i = 0; i < 17; i++) {
if (names[i] == note) {
int newduration = duration/SPEE;
playTone(tones[i], newduration);
}
}
333333333333
3333333333333333
****9***99*999999999999999999999999999++++++++
}
void setup() {
lcd.begin(16, 2);
pinMode(speakerPin, OUTPUT);
}
void loop() {
for (int i = 0; i < length; i++) {
lcd.setCursor(0,0);
lcd.print(lyric1[i]);
lcd.setCursor(0,1);
lcd.print(lyric2[i]);
if (notes[i] == ' ') {
delay(beats[i] * tempo); // rest
} else {
playNote(notes[i], beats[i] * tempo);
}
// pause between notes
delay(tempo);
}
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int speakerPin = 9;
int length = 28; // the number of notes
char notes[] = "GGAGcB GGAGdc GGxecBA yyecdc";
int beats[] = { 2, 2, 8, 8, 8, 16, 1, 2, 2, 8, 8,8, 16, 1, 2,2,8,8,8,8,16, 1,2,2,8,8,8,16 };
String lyric1[] = {"Ha ", "Happy", "Happy Birth", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Ha ", "Happy", "Happy Birth", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Ha ", "Happy", "Happy Birth", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Ha ", "Happy", "Happy Birth", "Happy Birthday", "Happy Birthday", "Happy Birthday", "Happy Birthday"};
String lyric2[] = {" ", "", "", "", "To", "To You", "To You", " ", "", "", "", "To", "To You", "To You", " ", "", "", "", "Dear", "Dear Bret", "Dear Bretton", " ", "", "", "", "To", "To You", "To You"};
int tempo = 150;
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B',
'c', 'd', 'e', 'f', 'g', 'a', 'b',
'x', 'y' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014,
956, 834, 765, 593, 468, 346, 224,
655 , 715 };
int SPEE = 5;
// play the tone corresponding to the note name
for (int i = 0; i < 17; i++) {
if (names[i] == note) {
int newduration = duration/SPEE;
playTone(tones[i], newduration);
}
}
333333333333
3333333333333333
****9***99*999999999999999999999999999++++++++
}
void setup() {
lcd.begin(16, 2);
pinMode(speakerPin, OUTPUT);
}
void loop() {
for (int i = 0; i < length; i++) {
lcd.setCursor(0,0);
lcd.print(lyric1[i]);
lcd.setCursor(0,1);
lcd.print(lyric2[i]);
if (notes[i] == ' ') {
delay(beats[i] * tempo); // rest
} else {
playNote(notes[i], beats[i] * tempo);
}
// pause between notes
delay(tempo);
}