Scenario: Robots have overthrown our human society it is our job to appease our new robot masters by giving them a robot art show. We do this by creating a code that causes machines to do several entertaining functions.
What We Did: We created a song using code that causes a speaker to give different frequencies. The song in question is the Star Wars overture.
Process: you began by working on circuit diagrams and lighting lightbulbs. Once we finished, that we moved on to breadboards and used resistors, potentiometers, and LEDs. Our end goal in that lab was to make an LED blink repeatedly and controlled. And our final lab we got to work with a Coding system with a kit consisting of several wires LEDs speaker or a breadboard and a red board among other things.
Concepts: Circuit: A loop of conductive material from one battery terminal to the other
Series: A circuit in which resistance is arranged in a chain, as so that the current has only one path to take; The circuit for our project was in a series, since there was only one path for the current to go
Parallel: A circuit that has two or more paths for current to flow through
Resistance: The amount of slowing of current through an obstacle; Variable - r; Unit - Ω (Ohms); Equation in Series - r1+r2+r3+...; Equation in Parallel - 1/r1+1/r2+...=1/Answer
Current: Flow of charge/electricity through the circuit; Variable - i; Unit - A (Amps); Equation - i=V/r
Voltage: The potential energy difference from one side of a component to the other; Variable - V; Unit - V (Volts); Equation - V=ir
Power: The amount of flow with a potential energy difference; Variable - P; Unit - W (Watts); Equation - P=Vi
Our Code: const int buzzerPin = 8; //the buzzer is connected to pin 8
const int songLength = 109; //how many characters are in the song
char notes[] = "dddgDcbaGDcbaGDcbcadddgDcbaGDcbaGDcbcaddeecbaggabaesddeecbagDaa deecbaggabaesDDGFLDctagD dddgDcbaGDcbaGDcbcag"; //the notes the program plays
float beats[] = {0.33,0.33,0.33,2,2,0.33,0.33,0.33,2,1,0.33,0.33,0.33,2,1,0.33,0.33,0.33,2,0.33,0.33,0.33,2,2,0.33,0.33,0.33,2,1,0.33,0.33,0.33,2,1,0.33,0.33,0.33,2,0.75,0.25,1.5,0.5,0.5,0.5,0.5,0.5,0.33,0.33,0.33,0.66,0.33,1,0.75,0.25,1.5,0.5,0.5,0.5,0.5,0.5,0.75,0.25,2,0.5,0.5,1.5,0.5,0.5,0.5,0.5,0.5,0.33,0.33,0.33,0.66,0.33,1,0.75,0.25,0.66,0.33,0.66,0.33,0.66,0.33,0.66,0.33,4,3,0.33,0.33,0.33,2,2,0.33,0.33,0.33,2,1,0.33,0.33,0.33,2,1,0.33,0.33,0.33,4,1.5}; //how long each note is played for
int tempo = 400; //how fast the song goes, lower tempo = faster song
void setup() //defines information for later on { pinMode(buzzerPin, OUTPUT); //the buzzer pin, which is pin 8, will output info from the code to buzzer }
void loop() //will loop endlessly until the program is stopped
{ int i, duration; //i is a whole number that represents the duration of the song
for (i = 0; i < songLength; i++) // plays the next note until the note it's trying to play is greater than the length of the song { duration = beats[i] * tempo; // actual length of song is the length of the beat x the tempo of the song
if (notes[i] == ' ') // if there's a space... { delay(duration); // then pause for however long we specified } else // otherwise... { tone(buzzerPin, frequency(notes[i]), duration); //play the next note
delay(duration); // wait for tone to finish } delay(tempo/10); // Pause between notes for whatever the tempo is divided by 10 }
while(true){} // We only want to play the song once, so we'll pause forever: } int frequency(char note) { // This function takes a note, and returns the frequency we defined for that character
int i; const int numNotes = 13; // number of notes you have
char names[] = {'d','e','f','s','g','a','t','b','c','D','L','F','G'}; // The character we use to represent each note int frequencies[] = {294,330,349,370,392,440,466,494,523,587,622,698,784}; // The frequency for each character, where d is 294 hertz, e is 330, and so on
for (i = 0; i < numNotes; i++) // Step through each note { if (names[i] == note) // If the character is found... { return(frequencies[i]); // Return the frequency for that character } } return(0); // If it can’t find a character that matches, play a frequency of 0, which is effectively a rest }
Reflections: One thing I thought we did poorly on was using our time wisely, because on several occasions of when we needed to get something done we were not. And although the code and the song was a success we were on our toes if the entire time. But despite that, it's seems that Grant and I worked together quite nicely. We kept each other on track as much as we could. But even then, most the time only one of us was working. And although we could've done better on our project, like adding a light show to accompany the song, it turned out OK.