Robot Art Show
Our cicuit is a combination of the "Happy Birthday" arduino and the "RGB light" aruino. We programed our circuit to play "Twinkle, Twinkle, Little Star." at the same time, we had a RGB LED light flashing with the beat of the song. Each note had a different color, for example, when the note "c" plays, a green light flashes. To play the song we need a buzzer and the notes in our code.
CIRCTUT NOTES:
/*
SparkFun Inventor’s Kit
Circuit 2A - Buzzer
Play notes using a buzzer connected to pin 10
This sketch was written by SparkFun Electronics, with lots of help from the Arduino community.
This code is completely free for any use.
View circuit diagram and instructions at: https://learn.sparkfun.com/tutorials/sparkfun-inventors-kit-experiment-guide---v41
Download drawings and code at: https://github.com/sparkfun/SIK-Guide-Code
*/
//LEDs are connected to these pins
int RedPin = 9;
int GreenPin = 6;
int BluePin = 5;
int speakerPin = 10; //the pin that buzzer is connected to
void setup()
{
pinMode(speakerPin, OUTPUT); //set the output pin for the speaker
//set the LED pins to output
pinMode(RedPin, OUTPUT);
pinMode(GreenPin, OUTPUT);
pinMode(BluePin, OUTPUT);
}
void loop()
{
green(); //LED flashes green
play('c', 5); //twin
turnOff (); // turn off LED
delay(25); //wait 1/4 second
green(); //LED flashes green
play('c', 5); //kle
turnOff (); // turn off LED
blue(); //LED flashes blue
play('g', 5); //twin
turnOff (); // turn off LED
delay(25); //wait 1/4 second
blue(); //LED flashes blue
play('g', 5); //kle
turnOff (); // turn off LED
cyan(); //LED flashes cyan
play('a', 5); //lit
turnOff (); // turn off LED
delay(25); //wait 1/4 second
cyan(); //LED flashes cyan
play('a', 5); //tle
turnOff (); // turn off LED
blue(); //LED flashes blue
play('g', 5); //star
turnOff (); // turn off LED
blue(); //LED flashes blue
play('f', 5); //how
turnOff (); // turn off LED
delay(25); //wait 1/4 second
blue(); //LED flashes blue
play('f', 5); //I
turnOff (); // turn off LED
green(); //LED flashes green
play('e', 5); //won
turnOff (); // turn off LED
delay(25); //wait 1/4 second
green(); //LED flashes green
play('e', 5); //der
turnOff (); // turn off LED
cyan(); //LED flashes cyan
play('d', 5); //what
turnOff (); // turn off LED
delay(25); //wait 1/4 second
cyan(); //LED flashes cyan
play('d', 5); //you
turnOff (); // turn off LED
green(); //LED flashes green
play('c', 5); //are
play(' ', 1); //pause for 1 beat
blue(); //LED flashes blue
play('g', 5); //up
turnOff (); // turn off LED
delay(25); //wait 1/4 second
blue(); //LED flashes blue
play('g', 5); //ab
turnOff (); // turn off LED
blue(); //LED flashes blue
play('f', 5); //ove
turnOff (); // turn off LED
delay(25); //wait 1/4 second
blue(); //LED flashes blue
play('f', 5); //the
turnOff (); // turn off LED
green(); //LED flashes green
play('e', 5); //world
turnOff (); // turn off LED
delay(25); //wait 1/4 second
green(); //LED flashes green
play('e', 5); //so
turnOff (); // turn off LED
cyan(); //LED flashes magenta
play('d', 5); //high
turnOff (); // turn off LED
blue(); //LED flashes blue
play('g', 5); //like
turnOff (); // turn off LED
delay(25); //wait 1/4 second
blue(); //LED flashes blue
play('g', 5); //a
turnOff (); // turn off LED
blue(); //LED flashes blue
play('f', 5); //dia
turnOff (); // turn off LED
delay(25); //wait 1/4 second
blue(); //LED flashes blue
play('f', 5); //mond
turnOff (); // turn off LED
green(); //LED flashes green
play('e', 5); //in
turnOff (); // turn off LED
delay(25); //wait 1/4 second
green(); //LED flashes green
play('e', 5); //the
turnOff (); // turn off LED
cyan(); //LED flashes cyan
play('d', 5); //sky
turnOff (); // turn off LED
green(); //LED flashes green
play('c', 5); //twin
turnOff (); // turn off LED
delay(25); //wait 1/4 second
green(); //LED flashes green
play('c', 5); //kle
turnOff (); // turn off LED
blue(); //LED flashes blue
play('g', 5); //twin
turnOff (); // turn off LED
delay(25); //wait 1/4 second
blue(); //LED flashes blue
play('g', 5); //kle
turnOff (); // turn off LED
cyan(); //LED flashes cyan
play('a', 5); //lit
turnOff (); // turn off LED
delay(25); //wait 1/4 second
cyan(); //LED flashes cyan
play('a', 5); //tle
turnOff (); // turn off LED
blue(); //LED flashes blue
play('g', 5); //star
turnOff (); // turn off LED
blue(); //LED flashes blue
play('f', 5); //how
turnOff (); // turn off LED
delay(25); //wait 1/4 second
blue(); //LED flashes blue
play('f', 5); //I
turnOff (); // turn off LED
green(); //LED flashes green
play('e', 5); //won
turnOff (); // turn off LED
delay(25); //wait 1/4 second
green(); //LED flashes green
play('e', 5); //der
turnOff (); // turn off LED
cyan(); //LED flashes cyan
play('d', 5); //what
turnOff (); // turn off LED
delay(25); //wait 1/4 second
cyan(); //LED flashes cyan
play('d', 5); //you
turnOff (); // turn off LED
green(); //LED flashes green
play('c', 5); //are
while (true) {} //get stuck in this loop forever so that the song only plays once
}
void play( char note, int beats)
{
int numNotes = 14; // number of notes in our note and frequency array (there are 15 values, but arrays start at 0)
//Note: these notes are C major (there are no sharps or flats)
//this array is used to look up the notes
char notes[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C', 'D', 'E', 'F', 'G', 'A', 'B', ' '};
//this array matches frequencies with each letter (e.g. the 4th note is 'f', the 4th frequency is 175)
int frequencies[] = {131, 147, 165, 175, 196, 220, 247, 262, 294, 330, 349, 392, 440, 494, 0};
int currentFrequency = 0; //the frequency that we find when we look up a frequency in the arrays
int beatLength = 150; //the length of one beat (changing this will speed up or slow down the tempo of the song)
//look up the frequency that corresponds to the note
for (int i = 0; i < numNotes; i++) // check each value in notes from 0 to 14
{
if (notes[i] == note) // does the letter passed to the play function match the letter in the array?
{
currentFrequency = frequencies[i]; // Yes! Set the current frequency to match that note
}
}
//play the frequency that matched our letter for the number of beats passed to the play function
tone(speakerPin, currentFrequency, beats * beatLength);
delay(beats * beatLength); //wait for the length of the tone so that it has time to play
delay(50); //a little delay between the notes makes the song sound more natural
}
void red () {
//set the LED pins to values that make red
analogWrite(RedPin, 100);
analogWrite(GreenPin, 0);
analogWrite(BluePin, 0);
}
void orange () {
//set the LED pins to values that make orange
analogWrite(RedPin, 100);
analogWrite(GreenPin, 50);
analogWrite(BluePin, 0);
}
void yellow () {
//set the LED pins to values that make yellow
analogWrite(RedPin, 100);
analogWrite(GreenPin, 100);
analogWrite(BluePin, 0);
}
void green () {
//set the LED pins to values that make green
analogWrite(RedPin, 0);
analogWrite(GreenPin, 100);
analogWrite(BluePin, 0);
}
void cyan () {
//set the LED pins to values that make cyan
analogWrite(RedPin, 0);
analogWrite(GreenPin, 100);
analogWrite(BluePin, 100);
}
void blue () {
//set the LED pins to values that make blue
analogWrite(RedPin, 0);
analogWrite(GreenPin, 0);
analogWrite(BluePin, 100);
}
void magenta () {
//set the LED pins to values that make magenta
analogWrite(RedPin, 100);
analogWrite(GreenPin, 0);
analogWrite(BluePin, 100);
}
void turnOff () {
//set all three LED pins to 0 or OFF
analogWrite(RedPin, 0);
analogWrite(GreenPin, 0);
analogWrite(BluePin, 0);
}
/* CHART OF FREQUENCIES FOR NOTES IN C MAJOR
Note Frequency (Hz)
c 131
d 147
e 165
f 175
g 196
a 220
b 247
C 262
D 294
E 330
F 349
G 392
A 440
B 494
*/
CONTENT
We used series and parallele circuits to conect the wires. We also can ues the equation v=ir to determine the voltage, resistance and amps. To have the charge run through the entire circuit, we had to make an elctromagnetic feild. Making sure that each wire is in the right spot and connected to the correct pin is also very important.we had many problems making our circuit. One of the troubles we ran into was that our settup had to different wires going into the same pin. We also had trouble with the code because even one mispelled word will cause the code not to work.
REFLECTION
This project was a fun but very challenging project. I think for me it was very hard to comprehend all of the coding but I was good at setting up the boards and making the board work. I think i improved my consiencius learning brcause we had to overcome a lot of obstacles and problems we had to encounter. We had made a lot of mistakes during the final project but we made changes and found ways around these mistakes