Professional Documents
Culture Documents
//Used to keep track of how many leds are being used in the circuit
// The songlength tells the board how long the song will last, including notes and spaces
void setup()
{
pinMode(buzzerPin, OUTPUT);
int index;
pinMode(ledPins[index],OUTPUT);
//
}
void loop()
{
// Runs the programa and commands into a loop
int i, duration;
for (i = 0; i < songLength; i++) // Goes through the various arrays of the song
{
duration = beats[i] * tempo; // Duration of the song accounting for the notes, rests, and tempo
if (notes[i] == ' ') // Tells the board that a space is equal to a rest
{
delay(duration); // Tells the board to execute the rest
}
else // If there isn't a space just play the note like normal
{
tone(buzzerPin, frequency(notes[i]), duration);
delay(duration); // Allow the tone to complete
}
delay(tempo/10); // Makes a pause between notes
}
oneAfterAnotherNoLoop();
oneOnAtATime(); // Tells it to light up one led at a time and to go to the next one
pingPong(); // Next has the leds light up back and forth like a ball in ping pong
int i;
const int numNotes = 7; // Number of different notes in the song
void oneAfterAnotherNoLoop() // This function will light one LED, after another with a pause in between with a
delay time stated in the command. The no loop indicates this function will not repeat itself.
{
int delayTime = 100; // Time inbetween lights turning on in miliseconds
//Each of these lines of code turns on and LED and tells it to wait a certain amount of time.
digitalWrite(ledPins[0], HIGH);
delay(delayTime);
digitalWrite(ledPins[1], HIGH);
delay(delayTime);
digitalWrite(ledPins[2], HIGH);
delay(delayTime);
digitalWrite(ledPins[3], HIGH);
delay(delayTime);
digitalWrite(ledPins[4], HIGH);
delay(delayTime);
digitalWrite(ledPins[5], HIGH);
delay(delayTime);
digitalWrite(ledPins[6], HIGH);
delay(delayTime);
digitalWrite(ledPins[7], HIGH);
delay(delayTime);
digitalWrite(ledPins[8], HIGH);
delay(delayTime);
digitalWrite(ledPins[9], HIGH);
delay(delayTime);
// This turns off all the LED after a certain amount of time as definied by the delay time, this applies to the
above code.
digitalWrite(ledPins[8], LOW);
delay(delayTime);
digitalWrite(ledPins[7], LOW);
delay(delayTime);
digitalWrite(ledPins[6], LOW);
delay(delayTime);
digitalWrite(ledPins[5], LOW);
delay(delayTime);
digitalWrite(ledPins[4], LOW);
delay(delayTime);
digitalWrite(ledPins[3], LOW);
delay(delayTime);
digitalWrite(ledPins[2], LOW);
delay(delayTime);
digitalWrite(ledPins[1], LOW);
delay(delayTime);
digitalWrite(ledPins[0], LOW);
delay(delayTime);
}
for(index = 0; index <=8 ; index++) // Steps through each LED and turns it on
{
digitalWrite(ledPins[index], HIGH);
delay(delayTime);
}
{
digitalWrite(ledPins[index], HIGH); // Makes an LED turn on
digitalWrite(ledPins[index+4], HIGH); // Skips 4 of the LED's and turns the next one on
delay(delayTime); // Pause to slow down the sequence
digitalWrite(ledPins[index], LOW); // Makes the LED turn on
digitalWrite(ledPins[index+4], LOW); // Skips 4 of the LED's and turns the next one off
}
}
void randomLED()
{
int index;
int delayTime;