Tagged with rgb

Arduino RGB LED + Winamp

Yesterday I saw this posted by majordecibel on the arduino.cc forum. The main difference between mine and his is that i have no hardware. I'm using the same setup as this post except I created a new mod in the SVIS.dll.

the color is on a fade loop, and the brightness is determined by the music. pretty basic code, basic enough that I was able to build it in a few hours. when the delay is below 50ms the color transitions are rough. Also in my code I have it mapped to a min value of  80. this is so that when I have the Arduino unit behind my monitor it doesn't bug the hell out of me.

int blue = 3;
int green = 5;
int red = 6;
int pwr = 11;
long timer;
const long muxInterval = 20;
int mux = 0;
int color[3] = {0,255,255};
int data[10]; 
float percent;
void setup()
{
   Serial.begin(57600);
  pinMode(blue, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(pwr, OUTPUT);
  timer = millis();
}


void loop(){

 if (Serial.available() > 10) {
 byte i = Serial.read();

 if (int(i) == 255) {
 for (int c = 0; c <= 9; c++){
 data[c] = int(Serial.read());
}
 }
int total = ((data[2] + data[3]) / 2);
total = map(total,0,255,80,255);
//total = 200;
percent = total / 255.00;

   int redTotal =  ((color[2]*percent));
   int greenTotal = ((color[1]*percent));
   int blueTotal = ((color[0]*percent));


  analogWrite(pwr, total);
  analogWrite(red, color[2]);
  analogWrite(green, color[1]);
  analogWrite(blue, color[0]);

if (millis() - timer > muxInterval) { 
   timer = millis(); mux++; 
   if (mux > 1530){
     mux = 1;
   }
   if (mux >= 1 && mux <= 255) {
     color[2] -= 1;
   }
   if (mux >= 256 && mux <= 510) {
      color[0] += 1;
   }
   if (mux >= 511 && mux <= 765) {
     color[1] -= 1;
   }
   if (mux >= 766 && mux <= 1020) {
     color[2] += 1;
   }
   if (mux >= 1021 && mux <= 1275) {
     color[0] -= 1;
   }
   if (mux >= 1276 && mux <= 1530) {
     color[1] += 1;
   }
}
 }
}
Tagged , , ,