November 26, 2024, 12:15:31 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


RC4 Random Flicker

Started by gvg451, February 14, 2008, 08:09:06 AM

Previous topic - Next topic

gvg451

I am just learning PBASIC on a steep learning curve (at the moment) :).  I need to randomize 8 outputs using a Prop1 and 2 RC-4s.  I  saw Jon Williams code for Random Lamps(awesome) and modified it to work with serial commands to the RC-4s.  My problem is that when I turn the prop1 off and restart it, the code does not start running.  I have to press the reset button and then it starts right up.  I was thinking about setting p6 high and using it to reset the prop1 controller on start up, but I'm kind of stuck.  Any ideas?

Thanks
Garth

    ' =========================================================================
'
'   Original File...... Random_Lamps_v3.BS1
'   Purpose...
'   Original Author.... Jon Williams, EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL Trigger1         = PIN6
SYMBOL Baud             = OT2400

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

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Speed           = 7


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

SYMBOL  advance         = B0
SYMBOL  pntr1           = B1
SYMBOL  pntr2           = B2
SYMBOL  pntr3           = B3
SYMBOL  pntr4           = B4
SYMBOL  level1          = B5
SYMBOL  level2          = B6
SYMBOL  level3          = B7
SYMBOL  level4          = B8

SYMBOL  lottery         = W5                    ' random value
SYMBOL  level5          = B9

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

Reset:
  lottery = 1225                                ' seed the random value


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

Main:
  SEROUT Sio, Baud, ("!!!RC4", %00, "V")
  SERIN Sio, Baud, advance, pntr1

  RANDOM lottery
  advance = lottery // Speed + 1
  pntr1 = pntr1 + advance // 102
  READ pntr1, level1

  RANDOM lottery
  advance = lottery // Speed + 1
  pntr2 = pntr2 + advance // 102
  READ pntr2, level2

  RANDOM lottery
  advance = lottery // Speed + 1
  pntr3 = pntr3 + advance // 102
  READ pntr3, level3

  RANDOM lottery
  advance = lottery // Speed + 1
  pntr4 = pntr4 + advance // 102
  level5 = level4 + level3
  READ pntr4, level4


  SEROUT Sio, Baud, ("!RC4", %00, "S", level1, level2, level3, level4)
  SEROUT Sio, Baud, ("!RC4", %01, "S", level5, level1, level4, level2)
  PAUSE 750
  GOTO Main


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


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


' -----[ User EEPROM ]-----------------------------------------------------

Glow_Table:
  EEPROM (000, 016, 031, 046, 060, 073, 085, 096)
  EEPROM (106, 113, 120, 124, 126, 127, 126, 122)
  EEPROM (117, 111, 102, 092, 081, 068, 054, 040)
  EEPROM (025, 009, 250, 234, 219, 205, 191, 178)
  EEPROM (166, 156, 147, 140, 134, 131, 129, 129)
  EEPROM (131, 135, 141, 149, 158, 168, 180, 193)
  EEPROM (207, 222, 237, 253, 237, 222, 207, 193)
  EEPROM (180, 168, 158, 149, 141, 135, 131, 129)
  EEPROM (129, 131, 134, 140, 147, 156, 166, 178)
  EEPROM (191, 205, 219, 234, 250, 009, 025, 040)
  EEPROM (054, 068, 081, 092, 102, 111, 117, 122)
  EEPROM (126, 127, 126, 124, 120, 113, 106, 096)
  EEPROM (085, 073, 060, 046, 031, 016)

JonnyMac

Congrats to you for giving it a try -- that's the best way to learn.  In your program you have mixed commands and that may be creating an issue... still, your Prop-1 should start running at power-up and not require pressing the reset button.

Here's a simple randomizer for two RC-4s that uses the "S" command correctly.  In the RC-4, "S" should be followed by just one byte.  The extra bytes in your program could, if they're the right values, be causing the RC-4s to do odd things.

' =========================================================================
'
'   File...... Random_RC-4.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN


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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0


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

SYMBOL  idx             = B2
SYMBOL  relays          = B3

SYMBOL  timer           = W4
SYMBOL  lottery         = W5
SYMBOL   lottoLo        =  B10
SYMBOL   lottoHi        =  B11


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

Reset:


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

Main:
  FOR idx = 1 TO 3
    RANDOM lottery
  NEXT

  relays = lottoLo
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  relays = relays / 16
  SEROUT Sio, Baud, ("!RC4", %01, "S", relays)

  timer = lottoHi / 2
  PAUSE timer
  GOTO Main


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


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


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