November 24, 2024, 10:06:51 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.


hangman program

Started by lottafun4u, September 06, 2007, 12:33:47 PM

Previous topic - Next topic

lottafun4u

Hey John
Breck ask me to ask you for a sample program for the hangman prop that would create lifelike movements. We have an old scare factory single cylinder prop which we would like motion and sound. could you please show us a version of this so we won't have to recreate the wheel? Thanks, Bransons Haunted adventure.

JonnyMac

Like this?...

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


' -----[ Program Description ]---------------------------------------------
'
' Note: Serial communications on P7 requires the replacement of the ULN2803
'       with a ULN2003, or the removal of pin 1 of the ULN2803.
'
' 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  Sio             = 7                     ' remove setup jumper
SYMBOL  PIR             = PIN6                  ' P6 SETUP = DN
SYMBOL  Body            = PIN0


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

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


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

SYMBOL  idx             = B2                    ' loop counter
SYMBOL  shaker          = W4                    ' shake timer
SYMBOL  lottery         = W5                    ' random value


' -----[ EEPROM Data ]-----------------------------------------------------


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

Reset:
  DIRS = %00000001                              ' make P0 an output
  lottery = 1031


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

Main:
  RANDOM lottery                                ' stir the random value
  IF PIR = IsOff THEN Main                      ' wait for trigger
  shaker = 0                                    ' clear the shake timer

Start_Sound:
  SEROUT Sio, OT2400, ("!AP8", %00, "P", 0)     ' start sound 0

Thash_About:
  FOR idx = 1 TO 3
    RANDOM lottery                              ' stir the random value
  NEXT
  Body = lottery                                ' copy control bit to valve
  PAUSE CylinderTm                              ' allow cylinder to move
  shaker = shaker + CylinderTm                  ' update the timer
  IF shaker < ShakeTime THEN Thash_About        ' done yet?

Post_Delay:
  PINS = %00000000                              ' cylinder off
  PAUSE OffDelay                                ' delay retriggering

  GOTO Main
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Since PIRs can be a little twitchy, you probably want to use this version -- it makes sure the PIR is really on before activating the prop.

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


' -----[ Program Description ]---------------------------------------------
'
' Note: Serial communications on P7 requires the replacement of the ULN2803
'       with a ULN2003, or the removal of pin 1 of the ULN2803.
'
' 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  Sio             = 7                     ' remove setup jumper
SYMBOL  PIR             = PIN6                  ' P6 SETUP = DN
SYMBOL  Body            = PIN0


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

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0


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

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


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

SYMBOL  idx             = B2                    ' loop counter
SYMBOL  timer           = B3                    ' for PIR deboucing
SYMBOL  shaker          = W4                    ' shake timer
SYMBOL  lottery         = W5                    ' random value


' -----[ EEPROM Data ]-----------------------------------------------------


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

Reset:
  PINS = %0000000                               ' clear everything
  DIRS = %00000001                              ' make P0 an output

  PAUSE OffDelay                                ' delay between triggers
  timer = 0                                     ' clear timers
  shaker = 0


' -----[ 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

Start_Sound:
  SEROUT Sio, OT2400, ("!AP8", %00, "P", 0)     ' start sound 0

Thash_About:
  FOR idx = 1 TO 3
    RANDOM lottery                              ' stir the random value
  NEXT
  Body = lottery                                ' copy control bit to valve
  PAUSE CylinderTm                              ' allow cylinder to move
  shaker = shaker + CylinderTm                  ' update the timer
  IF shaker < ShakeTime THEN Thash_About        ' done yet?

  GOTO Reset
Jon McPhalen
EFX-TEK Hollywood Office