


ShiftBrite Usage OverviewUpdate: I have been working on documentation; a much more complete version is available here: http://docs.macetech.com/doku.php/shiftbrite ShiftBrites (and other LED products) are available in the macetech store: http://www.macetech.com/store/ ShiftBrites have been available for a while, and I haven't created an actual datasheet or hook-up diagram yet. I still need to do that, but this should at least provide enough information to understand what the ShiftBrite is doing, and how to control it. A ShiftBrite has an RGB LED and a small controller chip, the Allegro A6281. The A6281 provides 10-bit PWM and 7-bit current control for each of the red, green, and blue LEDs. The V+ and GND pins power both the LED and the control chip. ShiftBrites require up to 60mA per module when all LEDs are active. The supply voltage should be kept between 5.5 and 9 volts. I have had good results with 6V and 7.5V power supplies. The DI (Data In) pin carries the actual control information into the ShiftBrite. It is the input to an internal 32-bit shift register. Every time data is shifted into the controller, the binary value on the DI pin is placed in Bit 0 of the shift register, and the value in Bit 31 overflows out the DO (Data Out) pin to the next ShiftBrite in the chain. Data is shifted in using MSB (most significant bit first). The CI (Clock In) pin controls the shifting process. Each time the CI pin is sent to logic high and low, data is shifted into the DI pin and out of the DO pin. The CI signal is passed through the ShiftBrite to the CO (Clock Output) pin, so the next ShiftBrite can receive the bits from the DO line. The LI (Latch Input) pin causes the ShiftBrite to accept whatever is in its shift register as a new command. If you send the LI pin high and then low after 32 clocks, the first ShiftBrite in the chain has all new data from the DI pin. The second ShiftBrite contains whatever was already in the first ShiftBrite, and so on. To command all ShiftBrites in a chain, you must toggle the LI pin after you have shifted data to all ShiftBrites; 32 clock cycles times the number of ShiftBrites in the chain. The LI pin passes through to the LO (Latch Output) pin. The EI (Enable Input) turns the entire chain on and off. If it is sent to logic high, then it will blank all ShiftBrites. When EI is low, all ShiftBrites will display the colors specified previously. The EI pin passes through to the EO pin. Each color has 10 bits of the 32 bit command word, as shown in the above diagram. The 10 bits allow PWM (pulse width modulation) control of LED brightness to 1024 possible levels. This is only true if the remaining 2 bits are set to zero. Otherwise, the ShiftBrite enters a command mode that allows current control and other parameters. This should always be set as shown in the code below, unless you have a specific reason to do otherwise. Additional information is available at the bottom of page 7 in the A6281 datasheet. Since the control mode can set the ShiftBrite to unusable modes, it is a good idea to write the control register often. Most of my code writes it each time the color values are written. The following Arduino code illustrates using the built-in SPI hardware for faster updates, though it is not really needed for only two ShiftBrites. This code should flash two ShiftBrites (or ShiftBars, or MegaBrites) alternating red and blue. If a ShiftBrite Shield or Shifty VU Shield is used, you should only have to plug in the cables and attach an external power supply, taking care that the ShiftBrite signal names are matched to the shield signal names. Once you have this code working, you should be able to use it as a basis for any ShiftBrite application. Simply adjust the NumLEDs definition at the beginning of the program, and then write your desired color values from 0 to 1023 in the LEDChannels array. Once all the colors are in the array, call the WriteLEDArray() function and the ShiftBrites should switch to their new colors. #define clockpin 13 // CI #define enablepin 10 // EI #define latchpin 9 // LI #define datapin 11 // DI #define NumLEDs 2 int LEDChannels[NumLEDs][3] = {0}; int SB_CommandMode; int SB_RedCommand; int SB_GreenCommand; int SB_BlueCommand; void setup() { pinMode(datapin, OUTPUT); pinMode(latchpin, OUTPUT); pinMode(enablepin, OUTPUT); pinMode(clockpin, OUTPUT); SPCR = (1<<SPE)|(1<<MSTR)|(0<<SPR1)|(0<<SPR0); digitalWrite(latchpin, LOW); digitalWrite(enablepin, LOW); } void SB_SendPacket() { if (SB_CommandMode == B01) { SB_RedCommand = 120; SB_GreenCommand = 100; SB_BlueCommand = 100; } SPDR = SB_CommandMode << 6 | SB_BlueCommand>>4; while(!(SPSR & (1<<SPIF))); SPDR = SB_BlueCommand<<4 | SB_RedCommand>>6; while(!(SPSR & (1<<SPIF))); SPDR = SB_RedCommand << 2 | SB_GreenCommand>>8; while(!(SPSR & (1<<SPIF))); SPDR = SB_GreenCommand; while(!(SPSR & (1<<SPIF))); } void WriteLEDArray() { SB_CommandMode = B00; // Write to PWM control registers for (int h = 0;h<NumLEDs;h++) { SB_RedCommand = LEDChannels[h][0]; SB_GreenCommand = LEDChannels[h][1]; SB_BlueCommand = LEDChannels[h][2]; SB_SendPacket(); } delayMicroseconds(15); digitalWrite(latchpin,HIGH); // latch data into registers delayMicroseconds(15); digitalWrite(latchpin,LOW); SB_CommandMode = B01; // Write to current control registers for (int z = 0; z < NumLEDs; z++) SB_SendPacket(); delayMicroseconds(15); digitalWrite(latchpin,HIGH); // latch data into registers delayMicroseconds(15); digitalWrite(latchpin,LOW); } void loop() { LEDChannels[0][0] = 1023; LEDChannels[0][1] = 0; LEDChannels[0][2] = 0; LEDChannels[1][0] = 0; LEDChannels[1][1] = 0; LEDChannels[1][2] = 1023; WriteLEDArray(); delay(200); LEDChannels[0][0] = 0; LEDChannels[0][1] = 0; LEDChannels[0][2] = 1023; LEDChannels[1][0] = 1023; LEDChannels[1][1] = 0; LEDChannels[1][2] = 0; WriteLEDArray(); delay(200); }
Submitted by Garrett on Tue, 06/02/2009 - 00:43. |
Recent Comments
|
Thanks for the detailed
Thanks for the detailed information and example code!
Thanks for the example code,
Thanks for the example code, but aren't the comments for the pins wrong?
Shouldn't this:
#define clockpin 13 // DI
#define enablepin 10 // LI
#define latchpin 9 // EI
#define datapin 11 // CI
Be this:
#define clockpin 13 // CI
#define enablepin 10 // EI
#define latchpin 9 // LI
#define datapin 11 // DI
That's right...fixed!
That's right...fixed!
What is the maximum number
What is the maximum number of shiftbrites I can chain?
do you have an photo of back
do you have an photo of back side ?