Robot Art Show:
For this project my partners and I created a code for an arduino board. Our code instructs the arduino board to play a series of lights and hot crust buns on a buzzer. We learned to build circuits, follow circuit diagrams, create code and circuit diagrams.
Code:
const int buzzerPin = 3;
const int songLength = 19;
// Notes is an array of text characters corresponding to the notes
// in your song. A space represents a rest (no tone)
char notes[] = "bag bag ggggaaaabag"; // a space represents a rest
// Beats is an array of values for each note and rest.
// A "1" represents a quarter-note, 2 a half-note, etc.
// Don't forget that the rests (spaces) need a length as well.
int beats[] = {2,2,3,1,2,2,3,1,1,1,1,1,1,1,1,1,2,2,3};
// The tempo is how fast to play the song.
// To make the song play faster, decrease this value.
int tempo = 150;
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, HIGH); // Turn on the LED
digitalWrite(4, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(12, HIGH); // Turn on the LED
digitalWrite(5, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(11, HIGH); // Turn on the LED
digitalWrite(6, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(10, HIGH); // Turn on the LED
digitalWrite(7, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(9, HIGH); // Turn on the LED
digitalWrite(8, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(9, LOW); // Turn off the LED
digitalWrite(8, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(10, LOW); // Turn off the LED
digitalWrite(7, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(11, LOW); // Turn off the LED
digitalWrite(6, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(12, LOW); // Turn on the LED
digitalWrite(5, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(13, LOW); // Turn off the LED
digitalWrite(4, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(13, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(12, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(11, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(10, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(9, HIGH); // Turn on the LED
delay (200); // Wait for 0.2 seconds
digitalWrite(8, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(7, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(6, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(5, HIGH); // Turn on the LED
delay (200); // Wait for 0.2 seconds
digitalWrite(4, HIGH); // Turn on the LED
delay(250); // Wait for 0.2 seconds
digitalWrite(4, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(5, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(6, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(7, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(8, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(9, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(10, LOW); // Turn off the LED
delay (200); // Wait for 0.2 seconds
digitalWrite(11, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(12, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(13, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
int i, duration;
for (i = 0; i < songLength; i++) // step through the song arrays
{
duration = beats[i] * tempo; // length of note/rest in ms
if (notes[i] == ' ') // is this a rest?
{
delay(duration); // then pause for a moment
}
else // otherwise, play the note
{
tone(buzzerPin, frequency(notes[i]), duration);
delay(duration); // wait for tone to finish
}
delay(tempo/10); // brief pause between notes
}
// Repeat infintely unless instructed otherwise.
int frequency(char note)
// This function takes a note character (a-g), and returns the
// corresponding frequency in Hz for the tone() function.
int i;
const int numNotes = 8; // number of notes we're storing
{
// The following arrays hold the note characters and their
// corresponding frequencies. The last "C" note is uppercase
// to separate it from the first lowercase "c". If you want to
// add more notes, you'll need to use unique characters.
// For the "char" (character) type, we put single characters
// in single quotes.
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
// Now we'll search through the letters in the array, and if
// we find it, we'll return the frequency for that note.
for (i = 0; i < numNotes; i++) // Step through the notes
{
if (names[i] == note) // Is this the one?
{
return(frequencies[i]); // Yes! Return the frequency
}
}
return(0);} // We looked through everything and didn't find it,
// but we still need to return a value, so return
}
const int songLength = 19;
// Notes is an array of text characters corresponding to the notes
// in your song. A space represents a rest (no tone)
char notes[] = "bag bag ggggaaaabag"; // a space represents a rest
// Beats is an array of values for each note and rest.
// A "1" represents a quarter-note, 2 a half-note, etc.
// Don't forget that the rests (spaces) need a length as well.
int beats[] = {2,2,3,1,2,2,3,1,1,1,1,1,1,1,1,1,2,2,3};
// The tempo is how fast to play the song.
// To make the song play faster, decrease this value.
int tempo = 150;
void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(buzzerPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, HIGH); // Turn on the LED
digitalWrite(4, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(12, HIGH); // Turn on the LED
digitalWrite(5, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(11, HIGH); // Turn on the LED
digitalWrite(6, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(10, HIGH); // Turn on the LED
digitalWrite(7, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(9, HIGH); // Turn on the LED
digitalWrite(8, HIGH);
delay(250); // Wait for 0.25 seconds
digitalWrite(9, LOW); // Turn off the LED
digitalWrite(8, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(10, LOW); // Turn off the LED
digitalWrite(7, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(11, LOW); // Turn off the LED
digitalWrite(6, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(12, LOW); // Turn on the LED
digitalWrite(5, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(13, LOW); // Turn off the LED
digitalWrite(4, LOW);
delay(250); // Wait for 0.25 seconds
digitalWrite(13, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(12, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(11, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(10, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(9, HIGH); // Turn on the LED
delay (200); // Wait for 0.2 seconds
digitalWrite(8, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(7, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(6, HIGH); // Turn on the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(5, HIGH); // Turn on the LED
delay (200); // Wait for 0.2 seconds
digitalWrite(4, HIGH); // Turn on the LED
delay(250); // Wait for 0.2 seconds
digitalWrite(4, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(5, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(6, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(7, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(8, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(9, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(10, LOW); // Turn off the LED
delay (200); // Wait for 0.2 seconds
digitalWrite(11, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(12, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
digitalWrite(13, LOW); // Turn off the LED
delay(200); // Wait for 0.2 seconds
int i, duration;
for (i = 0; i < songLength; i++) // step through the song arrays
{
duration = beats[i] * tempo; // length of note/rest in ms
if (notes[i] == ' ') // is this a rest?
{
delay(duration); // then pause for a moment
}
else // otherwise, play the note
{
tone(buzzerPin, frequency(notes[i]), duration);
delay(duration); // wait for tone to finish
}
delay(tempo/10); // brief pause between notes
}
// Repeat infintely unless instructed otherwise.
int frequency(char note)
// This function takes a note character (a-g), and returns the
// corresponding frequency in Hz for the tone() function.
int i;
const int numNotes = 8; // number of notes we're storing
{
// The following arrays hold the note characters and their
// corresponding frequencies. The last "C" note is uppercase
// to separate it from the first lowercase "c". If you want to
// add more notes, you'll need to use unique characters.
// For the "char" (character) type, we put single characters
// in single quotes.
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int frequencies[] = {262, 294, 330, 349, 392, 440, 494, 523};
// Now we'll search through the letters in the array, and if
// we find it, we'll return the frequency for that note.
for (i = 0; i < numNotes; i++) // Step through the notes
{
if (names[i] == note) // Is this the one?
{
return(frequencies[i]); // Yes! Return the frequency
}
}
return(0);} // We looked through everything and didn't find it,
// but we still need to return a value, so return
}
Content:
Electrical Circuit: a complete loop of conductive material from positive to negative sides of a power source.
Resistance (R): measure of how much current is slowed/how many obstacles; it is measured in ohms
Series: all parts of the circuit are connected on one path for the electricity (total resistance of resistors in a series)
Parallel: all parts of the circuit are connected across from each other forming two paths for the electricity (sum of resistors in a series=total resistance)
Ohm's Law: voltage = current x resistance (V=IR)
Kirchhoff's Laws:
Current Law: the sum of the currents going into a connection must equal the sum of the currents leaving the connection.
Voltage Law: the sum of the voltages around a circuit must equal zero.
Current (I) : "flow" of electricity through a circuit.
Voltage (V): potential energy drop across a component of a circuit.
Power (P): rate at which electrical energy is transferred by a circuit.
Resistance (R): measure of how much current is slowed/how many obstacles; it is measured in ohms
Series: all parts of the circuit are connected on one path for the electricity (total resistance of resistors in a series)
Parallel: all parts of the circuit are connected across from each other forming two paths for the electricity (sum of resistors in a series=total resistance)
Ohm's Law: voltage = current x resistance (V=IR)
Kirchhoff's Laws:
Current Law: the sum of the currents going into a connection must equal the sum of the currents leaving the connection.
Voltage Law: the sum of the voltages around a circuit must equal zero.
Current (I) : "flow" of electricity through a circuit.
Voltage (V): potential energy drop across a component of a circuit.
Power (P): rate at which electrical energy is transferred by a circuit.
Reflection:
I really enjoyed and learned a lot from this project. I think our group worked very well together and and we were able to collaborate easily. Some of our peaks were the light show and our efficiency level when we were putting the arduino board together. Some of our pits were we got side-tracked often and created many errors in our code. We were able to fix this problems by adjusting our codes and putting in needed quotations. We will work on staying on task in the future by focusing on our project and not getting off topic in discussions. All in all, our group worked very well together and we were able to accomplish our tasks.