November 24, 2024, 03:06:12 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


ShiftBrite Programming

Started by ScaryTinker, May 22, 2008, 03:25:59 PM

Previous topic - Next topic

ScaryTinker

Hi Jon,

I ran across the ShiftBrite product which is a RGB LED controller board that accepts serial commands.  http://macetech.com/blog/node/54.  Basically it looks like Shiftbrite is a carrier for an Allegro LED controller.  http://www.allegromicro.com/en/Products/Part_Numbers/6281/6281.pdf

This product seems like it could have a number of uses in the Halloween / Christmas prop arena.   I've read the the Allegro tech doc and it is way over my head.

Can you help me get started code wise?   I'd like to use a Prop-2 to control two ShiftBrite modules.  Ideally I'd like to be able to call a subroutine that changes the led color on both modules from the current color to the new color smoothly. 

ScaryTinker

JonnyMac

Steve,

Here's a starter program to try.  It counts on having the modules daisy-chained, passing the clock and data pins through the first module to the second.  The values in red1\green1\blue1 will go to the module that is connected to the Prop-2; the values in red2\green2\blue2 will go to the module connected to that.  A subroutine call updates both modules at the same time.

Once you get this simple program working then color fading is simply of matter of program loops with calls to the subroutine.  Let's get the modules under basic control first.

' =========================================================================
'
'   File...... ShiftBrite.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              see: http://creativecommons.org/licenses/by/3.0/us/
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

Clock           PIN     0
SData           PIN     1
Latch           PIN     2
Enable          PIN     3


' -----[ Constants ]-------------------------------------------------------


' -----[ Variables ]-------------------------------------------------------

cmd1            VAR     Byte
red1            VAR     Word
green1          VAR     Word
blue1           VAR     Word

cmd2            VAR     Byte
red2            VAR     Word
green2          VAR     Word
blue2           VAR     Word


' -----[ Initialization ]--------------------------------------------------

Reset:
  LOW Latch
  LOW Enable

  cmd1 = %01
  red1 = 127
  green1 = 127
  blue1 = 127
  cmd2 = %01
  red2 = 127
  green2 = 127
  blue2 = 127
  GOSUB Shift_Brite

  ' setup for color changing
  cmd1 = %00
  cmd2 = %00


' -----[ Program Code ]----------------------------------------------------

Main:
  red1 = 1023
  green1 = 0
  blue1 = 0
  red2 = 0
  green2 = 1023
  blue2 = 0
  GOSUB Shift_Brite
  PAUSE 1000

  red1 = 0
  green1 = 1023
  blue1 = 0
  red2 = 0
  green2 = 0
  blue2 = 1023
  GOSUB Shift_Brite
  PAUSE 1000

  red1 = 0
  green1 = 0
  blue1 = 1023
  red2 = 1023
  green2 = 0
  blue2 = 0
  GOSUB Shift_Brite
  PAUSE 1000

  GOTO Main


' -----[ Subroutines ]-----------------------------------------------------

Shift_Brite:
  ' module furthest from Prop-2
  SHIFTOUT SData, Clock, MSBFIRST, [cmd2\2, blue2\10, red2\10, green2\10]
  ' module connected to Prop-2
  SHIFTOUT SData, Clock, MSBFIRST, [cmd1\2, blue1\10, red1\10, green1\10]
  PULSOUT Latch, 1
  RETURN

' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office

macegr

Looks good...(I'm the guy who makes ShiftBrites, Steve gave me a heads-up).

I'd recommend running your Reset subroutine once per cycle, or every ten or so cycles. This makes sure the command registers are kept up-to-date, in case any noise gets on the digital lines and make the device enter the configuration mode.

As far as fading goes, you should have plenty of speed to get a smooth fade. I had some fading routines working fine on a Cubloc, which is a BASIC interpreter running on an AVR at about 36KHz instruction rate. Good results reported from Arduino users as well, and I have native AVR code running which of course is more than fast enough.

I'll keep an eye on this thread in case you run into any problems...let me know if you have ideas for future versions!

ScaryTinker

Works like a charm on the first try!  I reordered the pin assignments so I could use a servo cable to hook things up.

Thanks!

ScaryTinker

JonnyMac

Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

I am apparently doing something wrong. I hooked up the appropriate P0-P3 .w to the DI, LI, EI, and CI. I am only using one module. All I get is a blink of all the colors for a ms every second. Would using only one module instead of two with this program cause a problem?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Are you using a Prop-2 and the same code that Steve says works?
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

I am using a Prop-2 and the code posted above in this thread. Am I correct that I was to hook up the W pins from the prop-2 3pin headers to the DI, LI, EI, and CI on the ShiftBrite? I am powering from a seperate 6v 2amp power supply. Do I need a common ground?
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

Yes on both counts; use the Px.W pins (they connect to the BS2 processor) and you must have a common ground (likely problem).  Without a common reference point (ground) the signals going from the Prop-2 to the ShiftBright are meaningless.
Jon McPhalen
EFX-TEK Hollywood Office

gadget-evilusions

That's my problem then. It didn't occur to me until I was typing the last post. It should work fine once I get home an connect the ground.

Thanks as always.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

gadget-evilusions

The program worked perfectly once I had my common ground in place. Duh on my part.

I have been playing with loops for fading and setting a bunch of different color combinations. I found this calculator, http://www.drpeterjones.com/colorcalc/ , which will give RGB values for different colors. If you take the number given, multiply by 4 and use in conjunction with the above program, it seem to work perfectly. I have only tested about 20 colors, but so far they all look very good.
Brian
Evilusions LLC
www.evilusions.com for all your pneumatic components

JonnyMac

The x4 thing works because that is the same as shifting the value two bits to the left, converting a standard 8-bit value into a 10-bit value (with 8-bit resolution).

Glad you got everything going.
Jon McPhalen
EFX-TEK Hollywood Office