Here is my crude demo code. I will try and clean it up some tonight, test it a bit more, and add comments. I think probably it would make sense to setup a 2D array of LED color values with a variable for the number of LEDS in the chain. Right now it just shifts out the first LED color to the second LED in the chain each time. I also did not initialize the chip's current control register and should probably do that also.
Long term it would be nice to have some sort of light sequencer visual edit tool to generate the all of color data and timing.
Sparkfun has another somewhat more expensive RGB LED module (BlinkM) with such a tool - see http://thingm.com/products/blinkm. I looked at it and liked the idea, but perhaps it really needs more features.
Here is the format for the control registers:
PWM0 is Green, PWM1 is Red and PWM2 is Blue
<#include "mbed.h"
DigitalOut latch(p15);
DigitalOut enable(p16);
SPI spi(p11, p12, p13);
void RGB_LED(int red, int green, int blue) {
unsigned int low_color=0;
unsigned int high_color=0;
high_color=(blue<<4)|((red&0x3C0)>>6);
low_color=(((red&0x3F)<<10)|(green));
spi.write(high_color);
spi.write(low_color);
latch=1;
latch=0;
}
int main() {
int red=0;
int green=0;
int blue=0;
spi.format(16,0);
spi.frequency(500000);
enable=0;
latch=0;
wait(2);
for (red = 0; red<50; red = red+10) {
for (blue = 0; blue<50; blue = blue+10) {
for (green = 0; green<50; green = green+10)
{
RGB_LED( red, green, blue);
wait(.25);
}
}
}
}
Has anyone used one of these small Shiftbrite driver and RGB LED breakouts with mbed? Looks like it would make an interesting SPI demo project for students. The cost seems reasonable around $4 in qty. It has Allegro A6281 3-channel constant current LED driver and a bright RGB LED on a breakout board with the header pins.
Color LED breakout with driver