Shiftbrite Color LED breakout with driver

09 Feb 2011

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.

/media/uploads/4180_1/shiftbrite.jpg

Color LED breakout with driver

14 Feb 2011

Found this video of a Shiftbrite coffee table project.

02 Mar 2011

Just got a couple Shiftbrites. They are so bright you have to turn them down or it hurts your eyes. Here are a couple set to 50/1023 jumping around through RGB color space with a delay long enough to see the color.

Each module in the chain needs two 00s then three 10-bit color fields of shift data Then toggle latch pin high

A couple run OK off of mbed's 5V USB power, but you would need external power for a long chain and probably want 6+ volts

07 Apr 2011

Very interesting ! Can you quote some code ? I want to use it to make multicopter UFO lighting :)

08 Apr 2011

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:

Shiftbrite_Format

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);
            }
        }
    }

}
08 Apr 2011

Here is a simple sequencer for a chain of Shiftbrites:

#include "mbed.h"

//Bits for Shiftbrite latch and enable pins
DigitalOut latch(p15);
DigitalOut enable(p16);

// SPI connections for LED chain
SPI spi(p11, p12, p13);

//Serial PC(USBTX, USBRX);

// number of LEDS in chain
#define num_LEDS 2

// number of color values to sequence through
#define Sequence_Length 4

// Each LED'S RGB color values for each step in sequence
int LED_Color [Sequence_Length][num_LEDS][3] = {0};

// delay times in seconds for each RGB color value in sequence
// can be different for each sequence step
float Sequence_Delay[Sequence_Length];

void Write_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);
}

int main() {
    int i=0;
    int j=0;
    unsigned int init_command;
    spi.format(16,0);
    spi.frequency(500000);
    enable=0;
    latch=0;
    // Set currents using command mode
    // Do once during initialization
    // OK at power on, but a reset could set it to an invalid mode
    // Sets currents on R,G, and B to max value
    //
    // See page 7 in A6281 datasheet
    // This feature can be used to adjust for different LED
    // brightness levels
    init_command = 0x47F1FC7F;
    for (i=0; i<num_LEDS; i++) {
        spi.write(init_command>>16&0xFFFF);
        spi.write(init_command&0xFFFF);
    }
    wait(.000015);
    latch=1;
    wait(.000015);
    latch=0;

// Color data values for LEDs to sequence through
// Sequence step 0
    LED_Color[0][0][0] = 1023; //LED 0 RED
    LED_Color[0][0][1] = 0;
    LED_Color[0][0][2] = 0;
    LED_Color[0][1][0] = 0;
    LED_Color[0][1][1] = 0;
    LED_Color[0][1][2] = 0;
    Sequence_Delay[0] = 1;
// Sequence step 1
    LED_Color[1][0][0] = 0;
    LED_Color[1][0][1] = 0;
    LED_Color[1][0][2] = 0;
    LED_Color[1][1][0] = 0;
    LED_Color[1][1][1] = 1023; //LED 1 GREEN
    LED_Color[1][1][2] = 0;
    Sequence_Delay[1] = 2; //Stay at this value for 2 seconds
// Sequence step 2
    LED_Color[2][0][0] = 0;
    LED_Color[2][0][1] = 0;
    LED_Color[2][0][2] = 1023; //LED 0 BLUE
    LED_Color[2][1][0] = 0;
    LED_Color[2][1][1] = 0;
    LED_Color[2][1][2] = 0;
    Sequence_Delay[2] = 1;
// Sequence step 3
    LED_Color[3][0][0] = 1023; //LED 0 WHITE
    LED_Color[3][0][1] = 1023;
    LED_Color[3][0][2] = 1023;
    LED_Color[3][1][0] = 1023; //LED 1 WHITE
    LED_Color[3][1][1] = 1023;
    LED_Color[3][1][2] = 1023;
    Sequence_Delay[3] = 1;
// add more steps or LEDs if needed and change #defines

    wait(1);
    // Repeat Sequence Forever
    while (1) {
        //Step through the Sequence Values
        for (j = 0; j < Sequence_Length; j++) {
            // Step through each LED in chain at each sequence step
            for (i = 0; i < num_LEDS; i++) {
                //Writes 32-bits of RGB color data to LED using SPI hardware
                Write_LED( LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
  // Uncomment to get status info on serial port              
  //              printf("i= %d, j= %d\n\r",i,j);
  //              printf("   %d  %d  %d\n\r",LED_Color[j][i][0], LED_Color[j][i][1], LED_Color[j][i][2]);
            }
            //Load in new values just shifted out to LED chain by setting latch high
            wait(.000015);
            latch=1;
            wait(.000015);
            latch=0;
            //Delay for this step in the sequence
            wait(Sequence_Delay[j]);
        }
    }
}
08 Apr 2011

Many thanks ! This will be very helpful.

I think about some illumination with slow, continuous and quasi random colour transitions and your code is very good starting point.

08 Apr 2011

I was planning on adding a fade in feature - with the delay it could be fast or slow and it will only take a few more lines of code. Do you have any ideas on other lighting effects?

Could also make a flicker effect.

What kind of random effect would be useful?

08 Apr 2011

I made before some trials using 2 RGB LEDs to achieve the effect of smoothly changing colours in unpredictable sequence. I just used sin function (precalculated to save time on Arduino) and used PWM to make each colour bright as slow sin but with different period (like 7, 11, 17, 23, 29, 37 - only primary). The result is nice, as you can look at it and never know what kind of colour will appear next.

This kind effect could be applied either to linear array with different delays or to solour pulsing circles....

26 Apr 2011

I setup a new cookbook page to help people using ShiftBrites. It is located at http://mbed.org/users/4180_1/notebook/shiftbrite1/