I swear this wasn't filmed with a potato, I have awful bandwidth.
Song credit: The Yeah Yeah Yeah's - Heads Will Roll
I finally got a chance to clean up some of the test code I wrote for my LED strip controller, which can be found
here. With this code and my LED strip controller circuit, you can use an Arduino to control a 5050 LED strip so that it changes colors in response to music. I have it set to pulse and fade through a combination of red and blue hues in response to changes in volume.
I sought to create my lighting effects solely through code, and simply attached my audio signal straight to analog pin 3 on my Arduino Uno. I'm able to sense my signal through the use of the analogRead() command. The audio signal that I feed my Arduino changes in analog value based on a couple of factors. The Arduino sees this signal as a voltage source, and reads it as a value between 0 and 1024. Changing the volume of the input source and also variations in the rhythm and beat of the music cause this voltage value to fluctuate. For example, when I'm listening to house music and the bass drops, the volume rises and the voltage of the signal will rise up sharply. I can detect this rise, and change the color of my LED strip based on it.
My code is as follows:
#define REDPIN 5 //define what PWM pins are connected to the LED strip
#define GREENPIN 3
#define BLUEPIN 6
int b = 100; //define the variables that will be used to control red, green, and blue.
int r = 0; //these values don't matter too much
int g = 0;
void setup() {
pinMode(REDPIN, OUTPUT); //set the three PWM pins for output
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
pinMode(A3, INPUT); //set Analog pin 3 up for the audio signal
}
void loop() {
analogWrite(BLUEPIN, b); //change the color of the LED strip based on the values of r, g, and b.
analogWrite(REDPIN, r);
analogWrite(GREENPIN, g);
//using just my ipod, the max signal I get into A3 is 400 or so. If I had a signal that could reach 5v...
//... the input values I would get would range between 0 and 1024
if (analogRead(3)>325){ //if the signal from my ipod is greater in value than 325
r=255; //strobe white
b=255;
g=255;
}
else { //otherwise...
if (analogRead(3)>200) { //if the signal is greater than 200
r=(r+100); //increase the red and blue hues of the strip
b=(b+50);
}
else { //if the signal from the ipod is below 200
if (r>0 & b>0){ //and the values of red and blue are greater than 0
r=(r-25); //decrease each slowly (this creates a fading effect after each beat)
b=(b-10);
}
else { //if the values of red and blue fall below 0
r=0; //set them all equal to 0
b=0; //this is necessary to prevent each color from cycling through its min->max brightness
g=0;
}
}
}
}