I have some code that I found online (Update: Original post can be found at the old forum http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230560883/2, it was written by Studio Bricolage) however I can't figure out how to transform the code to work with a Common-Anode RGB LED using pull down resistors. Does anyone have any ideas of where I can begin to get this RGB LED to work? Hints and ideas are appreciated at this point since I've been banging my head on a well for a couple of weeks.
Here's the code.
//
// random tri-color fading LED *common cathode*
//
int value;
int w;
int x;
int y;
int gradation = 255;
float light_value;
long value_RED;
long value_GREEN;
long value_BLUE;
int ledpin1 = 9; // red LED connected to pwm pin 9 via 1K ohm resistor
int ledpin2 = 10; // blue LED connected to pwm pin 10 via 1K ohm resistor
int ledpin3 = 11; // green LED connected to pwm pin 11 via 1K ohm resistor
// LED cathode connected to ground
void setup()
{
// nothing for setup
}
void loop()
{
value_RED = 200 + random(56); // puts a random number between 0 and 255 into value_RED
value_BLUE = 200 + random(56); // puts a random number between 0 and 255 into value_BLUE
value_GREEN = 200 + random(56); // puts a random number between 0 and 255 into value_GREEN
for(value = 200; value <=255; value+=5) // ramp the number in "value" from 0 to 255
{
light_value = value_GREEN*((float)value/(float)gradation);
w = light_value; // transfer light_value into an integer
light_value = value_BLUE*((float)value/(float)gradation);
x = light_value; // transfer light_value into an integer
light_value = value_RED*((float)value/(float)gradation);
y = light_value; // transfer light_value into an integer
analogWrite(ledpin1, y); // increase the voltage in pin 9 from 0 to random volts
analogWrite(ledpin2, x); // increase the voltage in pin 10 from 0 to random volts
analogWrite(ledpin3, w); // increase the voltage in pin 11 from 0 to random volts
delay(30); // waits for 30 milli seconds to see the dimming effect
}
for(value = 255; value >=200; value-=5) // ramp the number in "value" from 255 to 0
{
light_value = value_GREEN*((float)value/(float)gradation);
w = light_value;
light_value = value_BLUE*((float)value/(float)gradation);
x = light_value;
light_value = value_RED*((float)value/(float)gradation);
y = light_value;
analogWrite(ledpin1, y); // increase the voltage in pin 9 from random to 0 volts
analogWrite(ledpin2, x); // increase the voltage in pin 10 from random to 0 volts
analogWrite(ledpin3, w); // increase the voltage in pin 11 from random to 0 volts
delay(30); // waits for 30 milli seconds to see the dimming effect
}
delay(700); // wait .7 seconds between fade up and down
}