November 22, 2024, 10:58:55 AM

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.


Help with Prop 1 programming

Started by Wraithrat, October 11, 2008, 07:19:06 PM

Previous topic - Next topic

Wraithrat

October 11, 2008, 07:19:06 PM Last Edit: October 11, 2008, 07:36:51 PM by Wraithrat
I have currently attempted (without success) at programming a prop 1 to do the following:
Using a PIR wait for a "victim", when triggered it will engage an actuator using an RC-4 to open the doors of a coffin.  After a short delay another actuator raises a skelleton (Albert) followed by one of 8 random sounds from an AP-8 board. then Albert will be lowered back down followed by the doors closing.  I'm not sure at this point what I am missing that the prop does not work.  It is probably something very basic that I have overlooked such as a jumper on one of the boards.  I used the same address (%00) for hte RC-4 and AP-8.  Is this acceptable or do they need to be different?  If you can help, please review the following code and give me input.  I appreciate all your help.  This program was put together from studying other posts.

' {$STAMP BS1}
' -----Albert Prop - Dennis Owen-------------------------------------------
' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' serial I/O
SYMBOL  PIR             = PIN6                  ' SETUP = DN

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

SYMBOL  IsOn            = 1                     ' active-high
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400

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

SYMBOL  pirTimer        = B2                    ' for PIR debouncing
SYMBOL  mnTimer         = B2                    ' minimum timer value
SYMBOL  mxTimer         = B3                    ' maximum timer value
SYMBOL  span            = B4                    ' random timer range
SYMBOL  sfx             = B5                    ' sound file
SYMBOL  tix             = W4                    ' timer value
SYMBOL  lottery         = W5                    ' random value
SYMBOL   Relays         = B0
SYMBOL   Doors          = BIT0
SYMBOL   Albert         = BIT1


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

Reset:
  PINS = %00000000                              ' outputs off (low)
  DIRS = %00111111                              ' make outputs

Reset_Accessories:
  SEROUT Sio, OT2400, ("!!!!!!!AP8", %00, "X","!RC4", %00, "X")

  tix = 300                                     ' 30 seconds
  GOSUB Timer                                   ' let PIR stabilize


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

Main:
  pirTimer = 0                                  ' reset the PIR timer

Wait_For_Victim:
  RANDOM lottery
  pirTimer = pirTimer + 25 * PIR                ' update timer
  IF pirTimer  < 250 THEN Wait_For_Victim       ' wait for 0.25 sec input

Randomized_Delay:
  mnTimer = 5                                    ' delay 0.5 to 2.0 secs
  mxTimer = 20
  GOSUB Random_Timer

Activate_Prop:
  Doors = IsOn                                    'open doors (Relay 1)
  GOSUB Update_RC4
  PAUSE 10                                        ' delay for 1 seconds
  Albert = IsOn                                   ' bring Albert up (Relay 2)
  GOSUB Update_RC4

Play_Randomized_Sound:
  GOSUB Random_Sound
  tix = 40                                      ' delay for 2.0 seconds
  GOSUB Timer

Fixed_Delay:
  tix = 20                                      ' delay for 2.0 seconds
  GOSUB Timer

Deactivate_Prop:
  Albert = IsOff                                ' Lay Albert back down to rest
  GOSUB Update_RC4
  PAUSE 10                                      ' wait for Albert to retract
    Doors = IsOff                               ' Close doors (Relay 1)
  GOSUB Update_RC4

Force_Release_Of_Trigger:
  IF PIR = IsOn THEN Force_Release_Of_Trigger

  tix = 100                                     ' 10 second delay
  GOSUB Timer                                   ' between "guests"

  GOTO Main

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

' Put minimum timer value in "mnTimer" and maximum timer value in "mxTimer"
' -- "mxTimer" must be larger than  "mnTimer"
' -- tix will be calculated from those two values
' -- tix value drops through to Timer subroutine

Random_Timer:
  tix = mxTimer - mnTimer + 1                   ' get span
  tix = lottery // tix + mnTimer                ' get random tix in range

  ' no RETURN; drops through to  "Timer"

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

' Put number of 0.1 second units in  "tix" before calling
' --  "tix" is destroyed by this subroutine
' -- maximum delay is 6553.6 seconds

Timer:
IF tix = 0 THEN Timer_Done                    ' expired?
   PAUSE 100                                   ' no, delay 0.1 second
   tix = tix - 1                               ' decrement timer
   RANDOM lottery                              ' restir random value
   GOTO Timer                                  ' check again

Timer_Done:
  RETURN

' -------------------------------------------------------------------------
Update_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN
' -------------------------------------------------------------------------

' Plays randomized sound
' -- does not monitor for repeats

Random_Sound:
  RANDOM lottery                                ' stir random value
  sfx = lottery // 8                            ' make 0..7
  SEROUT Sio, OT2400, ("!AP8", %00, "P", sfx)   ' play sound
  RETURN

JonnyMac

The program doesn't quite match your description.

Q) Do you just have the two heads?
Q) How long should the heads stay popped up? -- just for the scream, or longer?
Jon McPhalen
EFX-TEK Hollywood Office

Wraithrat

I am working on two seperate tasks and got them confused.  Have corrected and saved the original message.  Soving this one task will also help with the raising heads.  Sorry for the confusion

JonnyMac

October 11, 2008, 07:45:03 PM #3 Last Edit: October 11, 2008, 07:47:28 PM by JonnyMac
Here's how I would do what you described (versus what you were coding):

' =========================================================================
'
'   File...... Tombstones.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 11 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

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


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  relays          = B0
SYMBOL   Head1          =  BIT0
SYMBOL   Head2          =  BIT1

SYMBOL  status          = B1
SYMBOL   playing        =  BIT15

SYMBOL  sfx             = B2                    ' sound fx segment
SYMBOL  last            = B3

SYMBOL  timer           = W4
SYMBOL  lottery         = W5                    ' random #


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000000                              ' set outputs

  SEROUT Sio, Baud, ("!!!!!AP8", %00, "X", "!RC4", %00, "X")
  relays = %0000

  PAUSE 30000                                   ' PIR warm-up / show 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

Head_1:
  RANDOM lottery
  timer = lottery // 1501 + 500                 ' random, 0.5 to 2.0 secs
  PAUSE timer

  GOSUB Random_AP8                              ' play random scream
  Head1 = IsOn                                  ' pop-up head
  GOSUB Set_RC4
  GOSUB Wait_AP8                                ' let scream finish
  Head1 = IsOff                                 ' retract
  GOSUB Set_RC4

Head_2:
  RANDOM lottery
  timer = lottery // 1501 + 500                 ' random, 0.5 to 2.0 secs
  PAUSE timer

  GOSUB Random_AP8
  Head2 = IsOn
  GOSUB Set_RC4
  GOSUB Wait_AP8
  Head2 = IsOff
  GOSUB Set_RC4

  GOTO Reset


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

Random_AP8:
  RANDOM lottery
  sfx = lottery // 8
  IF sfx = last THEN Random_AP8                 ' don't repeat sfx
    last = sfx                                  ' save for next cycle

  ' drops through to Play_AP8

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

Play_AP8:
  SEROUT Sio, Baud, ("!AP8", %00, "P", sfx)
  RETURN

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

' Wait for AP-8 to finish playing

Wait_AP8:
  PAUSE 70
  SEROUT Sio, Baud, ("!AP8", %00, "G")
  SERIN  Sio, Baud, status
  IF playing = Yes THEN Wait_AP8
    RETURN

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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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


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

Wraithrat

Thanks for your help with the program.  I have applied your code to the next task I have which is to raise coffin doors then raise a skeleton from the coffin and play one of 8 random sounds as in the first example you gave me.  Following the sounds there will be a slight pause then lower the skeleton and finally close the doors.  I am using another PIR as the trigger.  I have coded the following and set everything up but get no response when I deploy the PIR.  Any suggestions for trouble-shooting?  Thanks.

'==========================================================================
'
'   File......ALBER PROP.BS1
'   Purpose...
'   Author....Dennis Owen
'             Assisted by Jon Williams, EFX-TEK
'             Copyright (c) 2008 EFX-TEK
'             Some Rights Reserved
'             --see http://creativecommons.org/licenses/by/3.0/
'   E-mail....dhowen@sfcn.org
'   Updated...12 OCT 2008
'   {$STAMP BS1}

'=========================================================================

'------[ Program Description ]---------------------------------------------
' 1/2 Coffin Prop coming out of ground that opens doors, raises a skeleton
' (Albert) then follows with one of 8 different random screams.  Albert
' then is lowered back into his coffin and the doors close.  Prop is
' triggered with a PIR from EFX-TEK.

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


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

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

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

SYMBOL  IsOn            = 1                     ' active-high
SYMBOL  IsOff           = 0

SYMBOL Yes              = 1
SYMBOL NO               = 0

SYMBOL  Baud            = OT2400               ' B/R jumper removed

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

SYMBOL  relays          = B0
SYMBOL  Doors           = BIT0
SYMBOL  Albert          = BIT1

SYMBOL  status          = B1
SYMBOL  Playing         = BIT15

SYMBOL  sfx             = B2                    ' sound fx segment
SYMBOL  last            = B3

SYMBOL   timer          = W4
SYMBOL   lottery        = W5                    ' random #


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000000                              ' set outputs

  SEROUT Sio, Baud, ("!!!!!!!AP8", %00, "X","!RC4", %00, "X")
  relays = %0000

  PAUSE 30000                                   ' PIR warm-up / slow delay


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

Main:
  Timer = 0                                  ' reset the PIR 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

Open_Doors:
  Doors = IsOn                               'open doors (Relay 1)
  GOSUB Set_RC4
  PAUSE 10                                   ' delay for 1 seconds

Raise_Albert:
  GOSUB Random_AP8                           ' play random scream
  Albert = IsOn                              ' bring Albert up (Relay 2)
  GOSUB Set_RC4
  GOSUB wait_AP8                             ' let scream finish
  PAUSE 30                                   ' wait for another 3 secs
  Albert = IsOff                              ' Lay Albert back down to rest
  GOSUB Set_RC4
  PAUSE 10                                   ' wait for Albert to retract
  Doors = IsOff                              ' Close doors (Relay 1)
  GOSUB Set_RC4

  GOTO Reset

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

Random_AP8:
  RANDOM lottery
  sfx = lottery // 8
  IF sfx = last THEN Random_AP8             'don't repeat sfx
    last = sfx                              ' save for next cycle

  ' drops through to Play_AP8

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

Play_AP8:
  SEROUT Sio, Baud, ("!AP9", %00, "P", sfx)
  RETURN

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

' wait for AP8 to finish

Wait_AP8:
  PAUSE 70
  SEROUT sio, baud, ("!AP8", %00, "G")
  SERIN  sio, baud, status
  IF playing = Yes THEN Wait_AP8
    RETURN

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

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN
' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------

JonnyMac

This is a new program, right? -- please start a new thread.  We are really trying hard to keep each thread on ONE topic (and a user is not considered a topic item ;D ). 
Jon McPhalen
EFX-TEK Hollywood Office