Arduino Board Plays happy Birthday
This project really helped me learn a lot about computer programing. My partner for this project was Caitlin Dwyer and we both really didn't understand how computers worked but we kept just going through the packets and experimenting and I feel I gained a lot of knowledge about the subject. We started by just doing a packet and questions about current, voltage and how to read a circuit diagram then we went onto the Arduino boards and put together our final piece.
Code:
#include <LiquidCrystal.h>
// Initialize the library with the pins we're using.
// (Note that you can use different pins if needed.)
LiquidCrystal lcd(12,11,5,4,3,2);
int speakerPin = 9; // setting speaker
int length = 28; // the number of notes
char notes[] = "GGAGcB GGAGdc GGxecBA yyecdc"; // The names of the notes being played
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 }; // how long the note holds
int tempo = 150; // how fast the song plays
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH); // high pitch of the speaker
delayMicroseconds(tone); // break between notes
digitalWrite(speakerPin, LOW); // low pitch of the speaker
delayMicroseconds(tone); // break between notes
}
}
void playNote(char note, int duration) {
char names[] = {'C', 'D', 'E', 'F', 'G', 'A', 'B',
'c', 'd', 'e', 'f', 'g', 'a', 'b',
'x', 'y' };
00, 1519, 1432, 1275, 1136, 1014,
956, 834, 765, 593, 468, 346, 224,
655 , 715 };
int SPEE = 3; // how fast the song plays
// play the tone corresponding to the note name
for (int i = 0; i < 17; i++) {
if (names[i] == note) { // if the char name match the char notes
int newduration = duration/SPEE; // create a new duration which is the old duration / the SPEE (the speed which is 3)
playTone(tones[i], newduration); // play the tone with the new duration
}
}
}
void setup()
{
pinMode(13, OUTPUT);
pinMode(speakerPin, OUTPUT);
lcd.begin(16, 2); // This is the amount of lines and characters the LCD has, 2 lines and 16 characters
lcd.clear(); // clears the LCD of any previous data remaining on the screen
// LCD invisible cursor starts on the top line first column
lcd.print("Happy Birthday"); // tells LCD what to say
lcd.setCursor(0,1); // sets the invisible cursor to one line lower
lcd.print("To You!!!"); // tells the LCD what to say
}
void loop() {
digitalWrite(13, HIGH); // Turn on the LED
for (int i = 0; i < length; i++) {
if (notes[i] == ' ') {
delay(beats[i] * tempo); // rest
} else {
playNote(notes[i], beats[i] * tempo); // paly notes with beat and tempo
}
// pause between notes
delay(tempo);
}
Content
Circuit: a continuous loop of conductive materials from the positive side of the battery to the negative side
Resistance: a measurement of how much the current is slowed or how many obstacles it has to overcome
Current: the flow of electricity through a circuit
Voltage: the potential energy that drops across a component of a circuit
Power(electrical): the rate of which electrical energy is transferred by a circuit
Resistance: a measurement of how much the current is slowed or how many obstacles it has to overcome
Current: the flow of electricity through a circuit
Voltage: the potential energy that drops across a component of a circuit
Power(electrical): the rate of which electrical energy is transferred by a circuit
Reflection
Overall this project was very challenging, but rewarding when we got our project all together and working. Some peaks of this project was when I figured out how to create my own code and got it to work and also when we got the light to blink with the song. some pits were that both Caitlin and I didn't really know where to start so we did have a little trouble in the beginning understanding the material. I learned myself how to program a code into what the computer reads and also how to read a circuit diagram which was probably the hardest part to learn for me. I could improve on challenging myself with this project and to do more with it. I really enjoyed learning how a computer really worked.