Experimenting with RGB Leds at Dayton Diode

I go these RGB leds from Radioshack the other day. They have a common cathode and three leads for each of the colors. My goal today was to see if I could get a fairly seamless color changing effect out of the light using the analog out (PWM) from an Arduino.

Here is a video of my results from todays efforts, I think it came out OK, although the led is pretty bright so a lot of the color gets blown out:




The code I used was directly based on the example program in the Arduino IDE called Fade. Instead of just fading one LED, now I fade three at different rates.

int brightnessr = 0;
int brightnessg = 0;
int brightnessb = 0;
int fadeAmountr = 1;
int fadeAmountg = 2;
int fadeAmountb = 3;

void setup() {
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}

void loop() {
analogWrite(9, brightnessr);
analogWrite(10, brightnessg);
analogWrite(11, brightnessb);

brightnessr = brightnessr + fadeAmountr;
brightnessg = brightnessg + fadeAmountg;
brightnessb = brightnessb + fadeAmountb;

if (brightnessr == 0 || brightnessr == 255) {
fadeAmountr = -fadeAmountr ;
}

if (brightnessg == 0 || brightnessg == 255) {
fadeAmountg = -fadeAmountg ;
}

if (brightnessb == 0 || brightnessb == 255) {
fadeAmountb = -fadeAmountb ;
}

delay(60);
}

I hope to in the future turn this into a full RGB LED sphere, with individually addressable LEDs.

1 comment:

Archive