November 24, 2024, 02:48:03 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.


I need of program

Started by robbob, September 22, 2007, 09:36:59 PM

Previous topic - Next topic

robbob

The program will control two air cylinders for a hangman prop . would like to run for 12 seconds in some kind of random movement of the two cylinders , this will be on a prop 1 control
the prop will be triggered by actor
or would like to use pir sensor

JonnyMac

Give this a try; it will work with a PIR or a normally-open button connected between P6.W and P6.R.

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


' -----[ Program Description ]---------------------------------------------
'
' Note: All delays are expressed in milliseconds (1/1000 sec), hence a
'       delay value of 20000 is equal to 20 seconds.


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


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

SYMBOL  PIR             = PIN6                  ' P6 SETUP = DN
SYMBOL  Leg2            = PIN1
SYMBOL  Leg1            = PIN0


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


' ************************
' Program Adjustments Here
' ************************

SYMBOL  CylinderTm      = 50                    ' cyclinder activation time
SYMBOL  ShakeTime       = 12000                 ' total shake time
SYMBOL  OffDelay        = 20000                 ' miminum off time


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

SYMBOL  lottery         = W0                    ' random value
SYMBOL  timer           = W1
SYMBOL  idx             = B2                    ' loop counter


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

Reset:
  PINS = %00000000                              ' clear everything
  DIRS = %00000011                              ' P0 and P1 are outputs

  PAUSE OffDelay                                ' delay between triggers
  timer = 0                                     ' clear timer (for PIR)


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

Main:
  RANDOM lottery                                ' stir the random value
  PAUSE 10                                      ' loop pad
  timer = timer + 10 * PIR                      ' update debounce timer
  IF timer < 250 THEN Main                      ' wait for valid signal

  timer = 0                                     ' clear timer (for moves)

Thash_About:
  FOR idx = 1 TO 3
    RANDOM lottery                              ' stir the random value
  NEXT
  Leg1 = BIT1                                   ' update valves
  Leg2 = BIT2
  PAUSE CylinderTm                              ' allow cylinders to move
  timer = timer + CylinderTm                    ' update the timer
  IF timer < ShakeTime THEN Thash_About         ' done yet?

  GOTO Reset
Jon McPhalen
EFX-TEK Hollywood Office