May 20, 2024, 10:25:16 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


MHC Demo Program -- Shaker (MIB, Electric Chair, Hangman, etc.)

Started by JonnyMac, June 10, 2010, 12:59:31 PM

Previous topic - Next topic

JonnyMac

In the intermediate programming class at MHC we developed a program that -- after triggering -- will randomly pulse an output for some period.  The pulsing and event timing parameters should be configurable to match the code to the kind of prop in use, so I've moved some values to the constants section.

Here's the program (will run on a Trainer if you have one):

' =========================================================================
'
'   File...... MHC_2010_Shaker.BS1
'   Purpose... Do randomized shaking for a given period
'   Author.... Jon Williams, EFX-TEK
'   E-mail.... teamefx@efx-tek
'   Started...
'   Updated... 10 JUN 2010
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

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

SYMBOL  Valve           = 0


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

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

SYMBOL  Baud            = OT2400

SYMBOL  PULSE_MIN       =   75                  ' min valve delay
SYMBOL  PULSE_MAX       =  250                  ' max valve delay
SYMBOL  SHAKE_TIME      = 5000                  ' shake duration


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

SYMBOL  delay           = W3                    ' allow long delays (>255)
SYMBOL  timer           = W4                    ' for debounce/event time
SYMBOL  lottery         = W5                    ' random #


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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00111111                              ' make P0-P5 outputs

  PAUSE 30000                                   ' PIR warm-up/post delay


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

Main:
  timer = 0                                     ' reset timer

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

  timer = 0

Shake_It:
  RANDOM lottery
  delay = PULSE_MAX - PULSE_MIN + 1             ' calculate span for //
  delay = lottery // delay + PULSE_MIN          ' caculate delay
  TOGGLE Valve
  PAUSE delay
  timer = timer + delay
  IF timer < SHAKE_TIME THEN Shake_It

  GOTO Reset


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


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


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