For this project our goal was to design and program something cool for our arduino board to do. My partner and I decided for a 007 theme. We used a buzzer to buzz to the beat of the 007 theme song and at the end of the song, LED lights light up and write out "007". We also had to code the computer to make this happen, so we found a code online for the song and I coded out all of the lights.
Here is it in action:
Here is it in action:
Code
#include "pitches.h" //gives the notes pitches to play at
#define NO_SOUND 0 // make the rests in music
//array of notes
int melody[] = {
NOTE_G4,NOTE_G4,NO_SOUND,NOTE_G4,NOTE_G4,NO_SOUND,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,
NOTE_B3,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_CS4,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_B3,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_CS4,NOTE_G3,NOTE_C4,NOTE_G3,
NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4, //notes of song
//Introduction
NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_DS5,NOTE_D5,NOTE_B4,NOTE_A4,NOTE_B4,
NOTE_E4,NOTE_G4,NOTE_DS5,NOTE_D5,NOTE_G4,NOTE_B4,
NOTE_B4,NOTE_FS5,NOTE_F5,NOTE_B4,NOTE_D5,NOTE_AS5,
NOTE_A5,NOTE_F5,NOTE_A5,NOTE_DS6,NOTE_D6,NO_SOUND //notes of song
};
// note duration: 1 = whole note, 2 = half note, 4 = quarter note, 8 = eighth note, etc.
int noteDurations[] = {
8,8,2,8,8,2,16,8,16,8,8,
2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,2,8,8,1,
8,4,8,4,8,8,
8,8,4,8,4,8,
4,8,4,8,3 //how long each note plays for
};
int pace = 1450; // change pace of music("speedy")
void setup()
{
for (int Note = 0; Note <97; Note++) //counter of Notes (54 limit the array)
{
int duration = pace/noteDurations[Note];//Adjust duration with the pace of music
tone(13, melody[Note],duration); //assign pin 13 to the buzzer
// to distinguish the notes, set a minimum time between them.
delay(duration*1.2);
}
pinMode(12, OUTPUT); //assign a row of LEDs to that pin #
pinMode(11, OUTPUT); //"
pinMode(10, OUTPUT); //"
pinMode(9, OUTPUT); //"
pinMode(8, OUTPUT); //"
pinMode(7, OUTPUT); //"
pinMode(6, OUTPUT); //"
pinMode(5, OUTPUT); //"
pinMode(4, OUTPUT);
}
void loop()
{
digitalWrite(12, HIGH); //turn on that row of LEDs
digitalWrite(11, HIGH); //"
digitalWrite(10, HIGH); //"
digitalWrite(9, HIGH); //"
digitalWrite(8, HIGH); //"
digitalWrite(7, HIGH); //"
digitalWrite(6, HIGH); //"
digitalWrite(5, HIGH); //"
digitalWrite(4, HIGH);
}
#define NO_SOUND 0 // make the rests in music
//array of notes
int melody[] = {
NOTE_G4,NOTE_G4,NO_SOUND,NOTE_G4,NOTE_G4,NO_SOUND,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,
NOTE_B3,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_CS4,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_B3,NOTE_G3,NOTE_C4,NOTE_G3,NOTE_CS4,NOTE_G3,NOTE_C4,NOTE_G3,
NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4, //notes of song
//Introduction
NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_E4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_F4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_E4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_G4,NOTE_E4,NOTE_E4,NOTE_E4,
NOTE_DS5,NOTE_D5,NOTE_B4,NOTE_A4,NOTE_B4,
NOTE_E4,NOTE_G4,NOTE_DS5,NOTE_D5,NOTE_G4,NOTE_B4,
NOTE_B4,NOTE_FS5,NOTE_F5,NOTE_B4,NOTE_D5,NOTE_AS5,
NOTE_A5,NOTE_F5,NOTE_A5,NOTE_DS6,NOTE_D6,NO_SOUND //notes of song
};
// note duration: 1 = whole note, 2 = half note, 4 = quarter note, 8 = eighth note, etc.
int noteDurations[] = {
8,8,2,8,8,2,16,8,16,8,8,
2,4,2,4,2,4,2,4,2,4,2,4,2,4,2,4,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,16,16,8,4,8,8,8,
8,2,8,8,1,
8,4,8,4,8,8,
8,8,4,8,4,8,
4,8,4,8,3 //how long each note plays for
};
int pace = 1450; // change pace of music("speedy")
void setup()
{
for (int Note = 0; Note <97; Note++) //counter of Notes (54 limit the array)
{
int duration = pace/noteDurations[Note];//Adjust duration with the pace of music
tone(13, melody[Note],duration); //assign pin 13 to the buzzer
// to distinguish the notes, set a minimum time between them.
delay(duration*1.2);
}
pinMode(12, OUTPUT); //assign a row of LEDs to that pin #
pinMode(11, OUTPUT); //"
pinMode(10, OUTPUT); //"
pinMode(9, OUTPUT); //"
pinMode(8, OUTPUT); //"
pinMode(7, OUTPUT); //"
pinMode(6, OUTPUT); //"
pinMode(5, OUTPUT); //"
pinMode(4, OUTPUT);
}
void loop()
{
digitalWrite(12, HIGH); //turn on that row of LEDs
digitalWrite(11, HIGH); //"
digitalWrite(10, HIGH); //"
digitalWrite(9, HIGH); //"
digitalWrite(8, HIGH); //"
digitalWrite(7, HIGH); //"
digitalWrite(6, HIGH); //"
digitalWrite(5, HIGH); //"
digitalWrite(4, HIGH);
}
Concepts
Power(P)- rate of doing work or amount of energy used per unit time. P = W/t. Measured in watts.
Circuit - a circuit is a closed loop conductive material from positive to negative sides of a power source.
Resistance(R) - a measure of how much resistance the current encounters. In series, resistor values add, and in parallel, 1/R(total) = 1/R(1) + 1/R(2) + 1/R(3). R = V/I Measured in ohms.
Current(I) - electricity through a circuit. I = V/R. Measured in amps.
Voltage(V) - potential energy drop across a component of a circuit. V= IR. Measured in volts.
Circuit - a circuit is a closed loop conductive material from positive to negative sides of a power source.
Resistance(R) - a measure of how much resistance the current encounters. In series, resistor values add, and in parallel, 1/R(total) = 1/R(1) + 1/R(2) + 1/R(3). R = V/I Measured in ohms.
Current(I) - electricity through a circuit. I = V/R. Measured in amps.
Voltage(V) - potential energy drop across a component of a circuit. V= IR. Measured in volts.
Reflection
Yet another successful project completed and past. I felt really good about this project because I took a lot of leadership and got the job done efficiently. I felt that I could have payed attention more and have been less distracted. Overall this project was very successful and can't wait for the next one.