Lab 01 – Disco Lights

I tried to play around with the lights and more than a loop, I thought I could make it groovy and hence, chose to sync the lights with the legendary disco number Stayin’ Alive by the BeeGees (click for video; may be too loud though).

To get the different accents and beats, I set three connections in parallel and I placed the green and the yellow LEDs in serial to indicate a stronger third beat. I added the tempo variable in the code itself so if we change the song to, say a slower tempo in 4/4 time, this can be adjusted too! A slightly more varied drumbeat can also be incorporated!

Code:


int ledPin = 13; // goes to yellow and green
int ledPinTwo = 12; // goes to red
int ledPinThree = 11; // goes to blue

void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(ledPinTwo, OUTPUT);
pinMode(ledPinThree, OUTPUT);
}
void loop()
{

// Drumbeat pattern (each column is one beat)
// YG: 1100 0000 0000 0000
// R: 1100 1100 1100 1100
// B: 1100 0000 1100 0000
// Tempo for Stayin' Alive: 104 BPM

digitalWrite(ledPin, HIGH);
digitalWrite(ledPinTwo, HIGH);
delay(30000/104);
digitalWrite(ledPin, LOW);
digitalWrite(ledPinTwo, LOW);
delay(30000/104);

digitalWrite(ledPinTwo, HIGH);
delay(30000/104);
digitalWrite(ledPinTwo, LOW);
delay(30000/104);

digitalWrite(ledPinTwo, HIGH);
digitalWrite(ledPinThree, HIGH);
delay(30000/104);
digitalWrite(ledPinTwo, LOW);
digitalWrite(ledPinThree, LOW);
delay(30000/104);

digitalWrite(ledPinTwo, HIGH);
delay(30000/104);
digitalWrite(ledPinTwo, LOW);
delay(30000/104);

}

Leave a Reply