The focus of this project was to teach us about electronic coding and robots. We learned about how circuits worked, and also how to calculate voltage, resistance, and current. To do this, we first worked out of a packet with a variety of experiments. When we completed this packet, we had a basic understanding of these principles. Then, we moved on to more complex boards
// 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.
Reflection :
I thought this project was very cool and interesting to learn about. I didn't particularly like this project as much which caused me to get more side tracked then usual. My group and I worked very well together and collaberated nicely. I didn't understand this project as much and my group was nice enough to take a step back and explain more complicated parts on the arduino boards. I thought our light show turned out very nice and well done and so did our song. I thought the process of making these circuits was very cool I especially liked make the lights all light up. I thought this was a very cool last project because it challenged my group and I.
// 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.
Reflection :
I thought this project was very cool and interesting to learn about. I didn't particularly like this project as much which caused me to get more side tracked then usual. My group and I worked very well together and collaberated nicely. I didn't understand this project as much and my group was nice enough to take a step back and explain more complicated parts on the arduino boards. I thought our light show turned out very nice and well done and so did our song. I thought the process of making these circuits was very cool I especially liked make the lights all light up. I thought this was a very cool last project because it challenged my group and I.