Shop OBEX P1 Docs P2 Docs Learn Events
Anyone ever played with mega-brites? — Parallax Forums

Anyone ever played with mega-brites?

TinkersALotTinkersALot Posts: 535
edited 2013-01-15 07:12 in BASIC Stamp
Here is what I am trying to drive with the code the follows:

http://docs.macetech.com/doku.php/megabrite

I can't say that I completely get their arduino code snip in their sample ( for example, what the heck is going on in the while loops in the SB_SendPacket() function? ).

Anyhow, the code below "seems to work" but I am not completely convinced that I have the bit mixing correct. So on the chance that somebody had tried these devices before I thought I would post this for some other eyes to look it over.

' {$STAMP BS2pe}
' {$PBASIC 2.5}

DataPin            PIN     0                       ' data pin
ClockPin           PIN     1                       ' shift clock
LatchPin           PIN     2                       ' latch outputs
EnablePin          PIN     4                       ' output enable

RLED           VAR    Word
GLED           VAR    Word
BLED           VAR    Word
TOREVERSE      VAR    Word
REVERSED       VAR    Word
LO_WORD        VAR    Word
HI_WORD        VAR    Word
COUNTER        VAR    Byte

Setup:
  LOW  EnablePin                                    ' turn on LED output
  LOW  LatchPin
  LOW  ClockPin


Main:
  DO
    FOR RLED = 1 TO 1000 STEP 30
      FOR BLED = 1 TO 1000 STEP 20
        FOR GLED = 1 TO 1000 STEP 10
          GOSUB RGB_LED
          PAUSE 1
        NEXT
      NEXT
    NEXT

    FOR GLED = 1000 TO 1 STEP -10
      FOR BLED = 1000 TO 1 STEP -20
        FOR RLED = 1000 TO 1 STEP -30
          GOSUB RGB_LED
          PAUSE 1
        NEXT
      NEXT
    NEXT

  LOOP
END


ReverseBits:
  REVERSED = 0
  COUNTER  = 16

'  DEBUG "INPUT: ", IBIN16 TOREVERSE

  DO WHILE ( COUNTER > 0 )
    REVERSED  = REVERSED << 1
    REVERSED  = REVERSED | ( TOREVERSE & 1 )
    TOREVERSE = TOREVERSE >> 1
    COUNTER   = COUNTER - 1
  LOOP

'  DEBUG " OUTPUT: " , IBIN16 REVERSED , CR
RETURN


DEBUG_WIRE_DATA:
  DEBUG "BLED ", IBIN10 BLED , CR
  DEBUG "RLED ", IBIN10 RLED , CR
  DEBUG "GLED ", IBIN10 GLED , CR

  DEBUG "HI_WORD/LO_WORD ", IBIN16 HI_WORD , "_" , IBIN16 LO_WORD, CR

  TOREVERSE = HI_WORD
  GOSUB ReverseBits
  DEBUG "WIRE_BITS ", IBIN16 REVERSED
  TOREVERSE = LO_WORD
  GOSUB ReverseBits
  DEBUG IBIN16 REVERSED, CR
RETURN


RGB_LED:
  LO_WORD = 0
  HI_WORD = 0

'  HI_WORD = ( BLED << 4 ) | ( ( RLED & $3C0 ) << 6 )
'  LO_WORD = ( ( ( RLED & $3F ) << 8 ) | ( GLED ) )

  ' 10bits G  10bits R  10bits B then two zeros
  '
  HI_WORD = ( ( BLED << 2 ) & $FFFC ) | ( ( RLED << 10 ) & $FC00 )
  LO_WORD =  RLED >> 6 | ( ( GLED << 6 ) & $FFC0 )

'  GOSUB DEBUG_WIRE_DATA

  SHIFTOUT DataPin, ClockPin, LSBFIRST, [HI_WORD]  ' send the bits
  SHIFTOUT DataPin, ClockPin, LSBFIRST, [LO_WORD]  ' send the bits

  HIGH  LatchPin
  PAUSE 1
  LOW   LatchPin
RETURN


Please don't bother to reply if you have to say something like "I have a solution but I won't post code here because blah-blah-blah" -- cuz frankly that kind of response does not help anybody at all.

Thanks, in advance, to anyone that may have some help for me here.

For more ideas on what can be done with these things, see:

http://mbed.org/users/4180_1/notebook/shiftbrite1/
Sign In or Register to comment.