November 22, 2024, 03:40:34 PM

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.


Updated Zombie Thrasher

Started by JonnyMac, October 15, 2013, 03:30:15 PM

Previous topic - Next topic

JonnyMac

I was assisting a customer with a thrashing loop and remembered that the BS1 does in fact have a MAX operator to prevent a value from exceeding a setpoint. That helped me clean up my thrashing algorithm that gets used in a lot of props -- it started, though, in the Casa Fear Zombie program.

Here's an update that lets you update two shoulder outputs while maintaining the state of other IO pins during the thrash routine.

' =========================================================================
'
'   File...... Casa_Fear_Zombie_2013.BS1
'   Purpose...
'   Author.... JonnyMac
'   E-mail....
'   Started...
'   Updated... 15 OCT 2013
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Sio     :: Serial IO to EFX-TEK accessories (RC-4, FC-4, etc.)
'            -- clip pin 1 of ULN2803 or replace with ULN2003
'
' Trigger :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'            -- connect N.O. button between P6.W and P6.R


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  LShoulder       = PIN1
SYMBOL  RShoulder       = PIN0


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

SYMBOL  VALVES          = %00000011             ' pins used for valves

SYMBOL  IS_ON           = 1                     ' for active-high in/out
SYMBOL  IS_OFF          = 0

SYMBOL  YES             = 1
SYMBOL  NO              = 0

SYMBOL  BAUD            = OT2400                ' B/R jumper removed


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

SYMBOL  idx             = B2                    ' loop index
SYMBOL  newvalves       = B3                    ' new valve bits
SYMBOL  last            = B4                    ' last valve outputs

SYMBOL  delay           = W3                    ' cycle delay (ms)
SYMBOL  timer           = W4                    ' for debounce/run timing
SYMBOL  lottery         = W5                    ' random #


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

Power_Up:
  lottery = 1031                                ' seed random #

Reset:
  PINS = %00000000                              ' clear everything
  DIRS = VALVES                                 ' set outputs

  PAUSE 20000                                   ' pir warm-up/retrigger delay


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' stir random #
  PAUSE 10                                      ' loop pad
  timer = timer + 10 * Trigger                  ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

Start_Audio:
  ' command your audio player here

Jump:
  PINS = PINS | VALVES                          ' both on
  PAUSE 1000

  timer = 10000                                 ' thrash for 10 seconds

Thrasher:
  FOR idx = 1 TO 3
    RANDOM lottery
  NEXT
  newvalves = lottery & VALVES                  ' filter valve bits

  IF newvalves = last THEN Thrasher             ' force change
    last = newvalves                            ' save for next cycle

  PINS = PINS &/ VALVES | newvalves             ' clear old, set new
  RANDOM lottery
  delay = lottery // 251 + 100 MAX timer        ' 100 to 350ms
  PAUSE delay                                   ' hold
  timer = timer - delay                         ' update timer
  IF timer > 0 THEN Thrasher                    ' time left?
    GOTO Reset


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


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


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