May 15, 2024, 02:00:46 PM

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.


Controlling more than one prop with one controller

Started by a94cobra, October 22, 2010, 09:23:35 PM

Previous topic - Next topic

a94cobra

Ok, I got started with my Halloween stuff.  Jonnymac helped me get started on the programming.  Thanks a million by the way.  

I have three props.  Got the first one all programmed up and working.  My question is, can you have several different props running independantly on one Prop-2 board?  Or will the programming only see the one triggered and run that routine until it resets?  I'm thinking this is the case, but asking to see, I could be wrong.

bsnut

October 22, 2010, 10:54:55 PM #1 Last Edit: October 22, 2010, 10:56:42 PM by bsnut
It is a pain to do on Prop2 or even on the Prop1. I am not saying it can't be done. Let me point you to the Prop1 area of the forums where we talked about it.
http://www.efx-tek.com/php/smf/index.php?topic=1492.msg8585#msg8585

Here's an article that Jon wrote in Nut and Volts
http://www.parallax.com/dl/docs/cols/nv/vol7/col/NV135.pdf

It should answer your question. If you have any more questions just ask.
William Stefan
The Basic Stamp Nut

bsnut

I have one question for you. Will these props on the Prop2, be trigger at the same time? If not, then you may not need follow my last post.
William Stefan
The Basic Stamp Nut

JonnyMac

If the props don't have to run at the same time, not a problem.  If they do, the programming is not fun and you're somewhat limited in the features you can employ.
Jon McPhalen
EFX-TEK Hollywood Office

a94cobra

I figured it would be difficult to run more than one at the same time.  This little guy probably doesn't multi-task natively. 

I am using a program like this.  http://www.efx-tek.com/php/smf/index.php?topic=1577.0

I was thinking of moddifying the do while section to recognize the three different triggers and to goto the one triggered first.  When that finishes and resets another trigger could be selected.  Any reason that is not doable?

I'm gonna give those links a look see.  May explain how to get this done.

JonnyMac

If you're doing simple pop-ups you can sometimes multi-task (with coarse timing), but the code is not easy to follow (I can because I've being writing BASIC Stamp programs for 16+ years).  I suggest you go with your idea of testing the triggers and the first one pressed runs. 
Jon McPhalen
EFX-TEK Hollywood Office

a94cobra

Hey Thanks for all the help.   I got everything up and running for the Halloween display.  Just set it up to trigger one at a time.  I am gonna try and write some new code to intertwine the Elvis and the Barrel props to "multi-task".  Now that I know I should buy a controller for each prop.  A couple basic Prop-1's are on the list for next year.  By the time I figured out I really needed more controllers and not more outputs on a controller, you were already sold out.  Gonna try and add audio controllers on for next year too.  This year I just wired simple relays to control speakers, audio already playing. 

Anyway, if anyone wants to take a look at what I ended up with, critique or give suggestions on easily "multi-tasking" those two props, I have just a few days to play with it.

Quote'
'   File...... Scott's Halloween Display '10
'   Purpose... Animate 3 props
'   Author.... a94cobra
'   E-mail.... a94cobra@gmail.com
'   Started... 10-20-10
'   Updated... 10-25-10
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Trigger1        PIN     14                      ' SETUP = DN   Barrel
Trigger2        PIN     12                      ' SETUP = DN   Elvis
Trigger3        PIN     10                      ' SETUP = DN   Monster

BarrelFogger    PIN     0                       ' relay, V+/OUT0
BarrelPopUp     PIN     1                       ' pop-up solenoid, V+/OUT1
BarrelSpitter   PIN     2                       ' water motor, V+/OUT2
BarrelAudio     PIN     3                       ' barrel audio, V+/OUT6

ElvisPopOut     PIN     5                       ' pop-out solenoid, V+/OUT5
ElvisAudio      PIN     6                       ' plays music, V+/OUT6

MonsterDoor     PIN     7                       ' raise shade, V+/OUT8 white/orange
MonsterMotion   PIN     8                       ' moves arms and mouth, V+/OUT9 white/brown
MonsterAudio    PIN     9                       ' plays monster growls, V+/OUT10 white/blue

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

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

Yes             CON     1
No              CON     0


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

delay           VAR     Word
lottery         VAR     Word


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000011 : DIRL = %11111111           ' set outputs

  PAUSE 3000                                    ' reset delay


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

Main:
  DO                                            ' mat switch selection
    RANDOM lottery
    IF Trigger1 > 0 THEN Barrel                 ' activate barrel prop
    IF Trigger2 > 0 THEN Elvis                  ' activate elvis prop
    IF Trigger3 > 0 THEN Monster                ' activate monster prop
    PAUSE 5                                     ' give 5 ms timing
  LOOP


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

Barrel:
  BarrelAudio = IsOn                            ' turn on sounds
  BarrelFogger = IsOn                           ' activate fogger relay
  delay = lottery // 2001 + 1000                ' random, 1 to 3 secs
  PAUSE delay                                   ' hold for our random delay

  BarrelPopUp = IsOn                            ' pop up
  PAUSE 3000                                    ' hold 3 secs

  BarrelFogger = IsOff                          ' kill fogger
  BarrelSpitter = IsOn                          ' shoot water
  PAUSE 1500                                    ' hold for 1.5 seconds
  BarrelSpitter = IsOff                         ' turn water off
  PAUSE 1500                                    ' hold for 1.5 seconds

  GOTO Reset                                    ' everything off

Elvis:
  PAUSE 6000                                    ' hold for 6 seconds
  ElvisAudio = IsOn                             ' play elvis' audio
  PAUSE 2000                                    ' hold for 2 seconds
  ElvisPopOut = IsOn                            ' activate elvis and strobe
  PAUSE 11000                                   ' hold for 11 seconds

  GOTO Reset                                    ' everything off

Monster:
  MonsterDoor = IsOn                            ' raise shade on monster
  PAUSE 5000                                    ' hold for 5 seconds
  MonsterMotion = IsOn                          ' activate arms and mouth
  MonsterAudio = IsOn                           ' turn on monster growls
  PAUSE 20000                                   ' hold for 20 seconds
  MonsterDoor = IsOff                           ' lower shade
  PAUSE 5000                                    ' hold for 5 seconds

  GOTO Reset                                    ' everything off

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


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

JonnyMac

October 26, 2010, 03:23:47 PM #7 Last Edit: October 27, 2010, 06:49:56 AM by JonnyMac
Just to show you how grueling running more than one prop from a single controller can be, I've setup a state-machine architecture and coded the barrel portion -- you do the rest!  Okay, I did it. ;D

Hint: You cannot use PAUSE.  Ever! (except where I have it in the trigger scan).  You must set a timer for the prop and then let it count down within a state.
 
Updated: 27 OCT

' =========================================================================
'
'   File...... Scott's Halloween Display '10  "Multi-Task"
'   Purpose... Animate 3 props
'   Author.... a94cobra
'   E-mail.... a94cobra@gmail.com
'   Started... 10-20-10
'   Updated... 10-26-10
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' Original program code created by JonnyMac

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


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

Trigger1        PIN     14                      ' SETUP = DN   Barrel
Trigger2        PIN     12                      ' SETUP = DN   Elvis
Trigger3        PIN     10                      ' SETUP = DN   Monster

MonsterAudio    PIN     9                       ' plays monster growls, V+/OUT9 white/blue
MonsterMotion   PIN     8                       ' moves arms and mouth, V+/OUT8 white/brown
MonsterDoor     PIN     7                       ' raise shade, V+/OUT7 white/orange

ElvisAudio      PIN     6                       ' plays music, V+/OUT6
ElvisPopOut     PIN     5                       ' pop-out solenoid, V+/OUT5

BarrelAudio     PIN     3                       ' barrel audio, V+/OUT3
BarrelSpitter   PIN     2                       ' water motor, V+/OUT2
BarrelPopUp     PIN     1                       ' pop-up solenoid, V+/OUT1
BarrelFogger    PIN     0                       ' relay, V+/OUT0


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

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

Yes             CON     1
No              CON     0


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

idx             VAR     Byte

triggers        VAR     Byte
trBarrel       VAR      triggers.BIT6          ' trigger bits
trElvis        VAR      triggers.BIT4
trMonster      VAR      triggers.BIT2

sBarrel         VAR     Byte                    ' prop states
sElvis          VAR     Byte
sMonster        VAR     Byte

tmrBarrel       VAR     Byte                    ' timers
tmrElvis        VAR     Byte
tmrMonster      VAR     Byte

lottery         VAR     Word


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000011 : DIRL = %11111111           ' set outputs


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

Main:
  triggers = %01010100                          ' arm triggers
  FOR idx = 1 TO 20                             ' create ~100ms delay
    RANDOM lottery                              ' (re)stir random #
    triggers = triggers & INH                   ' scan triggers
    PAUSE 5
  NEXT


Update_Timers:
  IF (tmrBarrel > 0) THEN
    tmrBarrel = tmrBarrel - 1                   ' update timer if running
  ENDIF
  IF (tmrElvis > 0) THEN
    tmrElvis = tmrElvis - 1
  ENDIF
  IF (tmrMonster > 0) THEN
    tmrMonster = tmrMonster - 1
  ENDIF


' ==============
' Barrel Process
' ==============
'
Run_Barrel:
  BRANCH sBarrel, [RB_0, RB_1, RB_2, RB_3, RB_4, RB_5]

  sBarrel = 0                                   ' fix busted state

RB_0:
  IF (trBarrel = IsOn) THEN                     ' have trigger?
    BarrelAudio = IsOn                          ' turn on sounds
    BarrelFogger = IsOn                         ' activate fogger relay
    tmrBarrel = lottery // 21 + 10              ' random, 1 to 3 secs
    sBarrel = 1                                 ' update state
  ENDIF
  GOTO Run_Elvis                                ' next prop/process

RB_1:
  IF (tmrBarrel = 0) THEN                       ' expired?
    BarrelPopUp = IsOn                          ' pop up
    tmrBarrel = 30                              ' hold 3 secs
    sBarrel = 2                                 ' update state
  ENDIF
  GOTO Run_Elvis

RB_2:
  IF (tmrBarrel = 0) THEN                       ' expired?
    BarrelFogger = IsOff                        ' kill fogger
    BarrelSpitter = IsOn                        ' shoot water
    tmrBarrel =  15                             ' hold for 1.5 seconds
    sBarrel = 3                                 ' update state
  ENDIF
  GOTO Run_Elvis

RB_3:
  IF (tmrBarrel = 0) THEN                       ' expired?
    BarrelSpitter = IsOff                       ' turn off watter
    tmrBarrel =  15                             ' hold for 1.5 seconds
    sBarrel = 4                                 ' update state
  ENDIF
  GOTO Run_Elvis

RB_4:
  IF (tmrBarrel = 0) THEN                       ' expired?
    BarrelAudio = IsOff                         ' kill audio
    tmrBarrel = 300                             ' 30s reset delay
    sBarrel = 5                                 ' update state
  ENDIF
  GOTO Run_Elvis

RB_5:
  IF (tmrBarrel = 0) THEN                       ' expired?
    sBarrel = 0                                 ' update state
    GOTO RB_0                                   ' check new trigger
  ENDIF
  GOTO Run_Elvis


' =============
' Elvis Process
' =============
'
Run_Elvis:
  BRANCH sElvis, [RE_0, RE_1, RE_2, RE_3, RE_4]

  sElvis = 0                                    ' fix busted state

RE_0:
  IF (trElvis = IsOn) THEN                      ' have trigger?
    tmrElvis = 60                               ' hold for 6 seconds
    sElvis = 1                                  ' update state
  ENDIF
  GOTO Run_Monster                              ' next prop/process

RE_1:
  IF (tmrElvis = 0) THEN                        ' expired?
    ElvisAudio = IsOn                           ' play elvis' audio
    tmrElvis = 20                               ' hold for 2 seconds
    sElvis = 2                                  ' update state
  ENDIF
  GOTO Run_Monster

RE_2:
  IF (tmrElvis = 0) THEN                        ' expired?
    ElvisPopOut = IsOn                          ' activate elvis and strobe
    tmrElvis = 110                              ' hold for 11 seconds
    sElvis = 3                                  ' update state
  ENDIF
  GOTO Run_Monster

RE_3:
  IF (tmrElvis = 0) THEN                        ' expired?
    ElvisAudio = IsOff                          ' everything off
    ElvisPopOut = IsOff
    tmrElvis = 300                              ' reset delay, 30s
    sElvis = 4                                  ' update state
  ENDIF
  GOTO Run_Monster

RE_4:
  IF (tmrElvis = 0) THEN                        ' expired?
    sElvis = 0                                  ' update state
    GOTO RE_0                                   ' check new trigger
  ENDIF
  GOTO Run_Monster


' ===============
' Monster Process
' ===============
'
Run_Monster:
  BRANCH sMonster,[RM_0, RM_1, RM_2, RM_3, RM_4]

  sMonster = 0                                  ' fix busted state

RM_0:
  IF (trMonster = IsOn) THEN                    ' have trigger?
    MonsterDoor = IsOn                          ' raise shade on monster
    tmrMonster = 50                             ' hold 5s
    sMonster = 1                                ' update state
  ENDIF
  GOTO Main                                     ' next prop/process

RM_1:
  IF (tmrMonster = 0) THEN                      ' expired?
    MonsterMotion = IsOn                        ' activate arms and mouth
    MonsterAudio = IsOn                         ' turn on monster growls
    tmrMonster = 200                            ' hold for 20 seconds
    sMonster = 2                                ' update state
  ENDIF
  GOTO Main

RM_2:
  IF (tmrMonster = 0) THEN                      ' expired?
    MonsterDoor = IsOff                         ' lower shade
    tmrMonster = 50                             ' hold for 5 seconds
    sMonster = 3                                ' update state
  ENDIF
  GOTO Main

RM_3:
  IF (tmrMonster = 0) THEN                      ' expired?
    MonsterMotion = IsOff
    MonsterAudio = IsOff
    tmrMonster = 300                            ' reset delay, 30s
    sMonster = 4                                ' update state
  ENDIF
  GOTO Main

RM_4:
  IF (tmrMonster = 0) THEN                      ' expired?
    sMonster = 0                                ' update state
    GOTO RM_0                                   ' check new trigger
  ENDIF
  GOTO Main


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


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


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

a94cobra

October 26, 2010, 09:10:29 PM #8 Last Edit: October 26, 2010, 09:17:00 PM by a94cobra
Awesome.  I never thought about state-machine architecture or that there was a term for it.  Was thinking of something else, prolly much more basic and crude than that.  I was just gonna simply check other triggers while running each process.  Yours is much neater.  Better use of the PBASIC code.

Couple of questions.  The Barrel and Elvis are the two I want to work at the same time.  Or will this let all three run together?  I am thinking this will run all three(which is perfectly fine).  I am to setup Elvis just like you did the Barrel?  With the branches like the Barrel?  Obvious coding changes of course.  I think I understand what needs to be done.  Just making sure before I go crazy coding.

Do I need to keep the same number of branches in each prop section?  Seems that would keep everything inline.  So if the Monster didn't have enough things that needed to happen, just make some branches that just don't do anything, except pass on control.  Correct?

JonnyMac

October 26, 2010, 09:48:08 PM #9 Last Edit: October 26, 2010, 09:52:42 PM by JonnyMac
QuoteOr will this let all three run together?

Yes, they can all run together, that is the point of this architecture.  My plate was very full today and I wasn't feeling well so that's as much as I could do -- see if you can fill in the rest; I'll help if you need


QuoteDo I need to keep the same number of branches in each prop section?

No, you just can't insert any PAUSE statements that would have negative affect on loop timing.  All state sections are a few lines of code so they don't take much time at all, and each "prop" is only running one state section per loop iteration.
Jon McPhalen
EFX-TEK Hollywood Office

a94cobra

I think I can handle it.  So many thanks for getting me on the right track.  Just wanted to make sure my logic wasn't going off the deep end before I got started.

a94cobra

October 26, 2010, 10:19:45 PM #11 Last Edit: October 26, 2010, 10:30:54 PM by a94cobra
Is the basic premise of the program correct?

I am gonna map each prop for what happens at what seconds and try and put code in the right states.  See how that works.  So things happen at the right time.

I obviously havn't changed the functions of the Elvis or Monster states from the original Barrel.  Gonna have to count my seconds and map all three props to see which commands go where.  

Quote' =========================================================================
'
'   File...... Scott's Halloween Display '10  "Multi-Task"
'   Purpose... Animate 3 props
'   Author.... a94cobra
'   E-mail.... a94cobra@gmail.com
'   Started... 10-20-10
'   Updated... 10-26-10
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' Original program code created by JonnyMac

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


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

Trigger1        PIN     14                      ' SETUP = DN   Barrel
Trigger2        PIN     12                      ' SETUP = DN   Elvis
Trigger3        PIN     10                      ' SETUP = DN   Monster

MonsterAudio    PIN     9                       ' plays monster growls, V+/OUT9 white/blue
MonsterMotion   PIN     8                       ' moves arms and mouth, V+/OUT8 white/brown
MonsterDoor     PIN     7                       ' raise shade, V+/OUT7 white/orange

ElvisAudio      PIN     6                       ' plays music, V+/OUT6
ElvisPopOut     PIN     5                       ' pop-out solenoid, V+/OUT5

BarrelAudio     PIN     3                       ' barrel audio, V+/OUT3
BarrelSpitter   PIN     2                       ' water motor, V+/OUT2
BarrelPopUp     PIN     1                       ' pop-up solenoid, V+/OUT1
BarrelFogger    PIN     0                       ' relay, V+/OUT0


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

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

Yes             CON     1
No              CON     0


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

idx             VAR     Byte

triggers        VAR     Byte
trBarrel       VAR      triggers.BIT6          ' trigger bits
trElvis        VAR      triggers.BIT4
trMonster      VAR      triggers.BIT2

sBarrel         VAR     Byte                    ' prop states
sElvis          VAR     Byte
sMonster        VAR     Byte

tmrBarrel       VAR     Byte                    ' timers
tmrElvis        VAR     Byte
tmrMonster      VAR     Byte

lottery         VAR     Word


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

Reset:
 OUTH = %00000000 : OUTL = %00000000           ' clear all
 DIRH = %00000011 : DIRL = %11111111           ' set outputs


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

Main:
 triggers = %01010100                          ' arm triggers
 FOR idx = 1 TO 20                             ' create ~100ms delay
   RANDOM lottery                              ' (re)stir random #
   triggers = triggers & INH                   ' scan triggers
   PAUSE 5
 NEXT


Update_Timers:
 IF (tmrBarrel > 0) THEN
   tmrBarrel = tmrBarrel - 1                   ' update timer if running
 ENDIF


' ==============
' Barrel Process
' ==============
'
Run_Barrel:
 BRANCH sBarrel,[RB_0, RB_1, RB_2, RB_3, RB_4, RB_5]

 sBarrel = 0                                   ' fix busted state

RB_0:
 IF (trBarrel = IsOn) THEN                     ' have trigger?
   BarrelAudio = IsOn                          ' turn on sounds
   BarrelFogger = IsOn                         ' activate fogger relay
   tmrBarrel = lottery // 21 + 10              ' random, 1 to 3 secs
   sBarrel = 1                                 ' update state
 ENDIF
 GOTO Run_Elvis                                ' next prop/process

RB_1:
 IF (tmrBarrel = 0) THEN                       ' expired?
   BarrelPopUp = IsOn                          ' pop up
   tmrBarrel = 30                              ' hold 3 secs
   sBarrel = 2                                 ' update state
 ENDIF
 GOTO Run_Elvis

RB_2:
 IF (tmrBarrel = 0) THEN                       ' expired?
   BarrelFogger = IsOff                        ' kill fogger
   BarrelSpitter = IsOn                        ' shoot water
   tmrBarrel =  15                             ' hold for 1.5 seconds
   sBarrel = 3                                 ' update state
 ENDIF
 GOTO Run_Elvis

RB_3:
 IF (tmrBarrel = 0) THEN                       ' expired?
   BarrelSpitter = IsOff                       ' turn off watter
   tmrBarrel =  15                             ' hold for 1.5 seconds
   sBarrel = 4                                 ' update state
 ENDIF
 GOTO Run_Elvis


RB_4:
 IF (tmrBarrel = 0) THEN                       ' expired?
   BarrelAudio = IsOff                         ' kill audio
   tmrBarrel = 300                             ' 30s reset delay
   sBarrel = 5                                 ' update state
 ENDIF
 GOTO Run_Elvis

RB_5:
 IF (tmrBarrel = 0) THEN                       ' expired?
   sBarrel = 0                                 ' update state
   GOTO RB_0                                   ' check new trigger
 ENDIF
 GOTO Run_Elvis


' =============
' Elvis Process
' =============
'
Run_Elvis:
   BRANCH sElvis,[RE_0, RE_1, RE_2, RE_3, RE_4, RE_5]

 sElvis = 0                                    ' fix busted state

RE_0:
 IF (trElvis = IsOn) THEN                      ' have trigger?
   BarrelAudio = IsOn                          ' turn on sounds
   BarrelFogger = IsOn                         ' activate fogger relay
   tmrElvis = lottery // 21 + 10               ' random, 1 to 3 secs
   sElvis = 1                                  ' update state
 ENDIF
 GOTO Run_Monster                              ' next prop/process

RE_1:
 IF (tmrElvis = 0) THEN                        ' expired?
   BarrelPopUp = IsOn                          ' pop up
   tmrElvis = 30                               ' hold 3 secs
   sElvis = 2                                  ' update state
 ENDIF
 GOTO Run_Monster

RE_2:
 IF (tmrElvis = 0) THEN                        ' expired?
   BarrelFogger = IsOff                        ' kill fogger
   BarrelSpitter = IsOn                        ' shoot water
   tmrElvis =  15                              ' hold for 1.5 seconds
   sElvis = 3                                  ' update state
 ENDIF
 GOTO Run_Monster

RE_3:
 IF (tmrElvis = 0) THEN                        ' expired?
   BarrelSpitter = IsOff                       ' turn off watter
   tmrElvis =  15                              ' hold for 1.5 seconds
   sElvis = 4                                  ' update state
 ENDIF
 GOTO Run_Monster


RE_4:
 IF (tmrElvis = 0) THEN                        ' expired?
   BarrelAudio = IsOff                         ' kill audio
   tmrElvis = 300                              ' 30s reset delay
   sElvis = 5                                  ' update state
 ENDIF
 GOTO Run_Monster

RE_5:
 IF (tmrElvis = 0) THEN                        ' expired?
   sElvis = 0                                  ' update state
   GOTO RE_0                                   ' check new trigger
 ENDIF
 GOTO Run_Monster


' ===============
' Monster Process
' ===============
'
Run_Monster:
   BRANCH sMonster,[RM_0, RM_1, RM_2, RM_3, RM_4, RM_5]

 sMonster = 0                                  ' fix busted state

RM_0:
 IF (trMonster = IsOn) THEN                    ' have trigger?
   BarrelAudio = IsOn                          ' turn on sounds
   BarrelFogger = IsOn                         ' activate fogger relay
   tmrMonster = lottery // 21 + 10             ' random, 1 to 3 secs
   sMonster = 1                                ' update state
 ENDIF
 GOTO Main                                     ' next prop/process

RM_1:
 IF (tmrMonster = 0) THEN                      ' expired?
   BarrelPopUp = IsOn                          ' pop up
   tmrMonster = 30                             ' hold 3 secs
   sMonster = 2                                ' update state
 ENDIF
 GOTO Main

RM_2:
 IF (tmrMonster = 0) THEN                      ' expired?
   BarrelFogger = IsOff                        ' kill fogger
   BarrelSpitter = IsOn                        ' shoot water
   tmrMonster =  15                            ' hold for 1.5 seconds
   sMonster = 3                                ' update state
 ENDIF
 GOTO Main

RM_3:
 IF (tmrMonster = 0) THEN                      ' expired?
   BarrelSpitter = IsOff                       ' turn off watter
   tmrMonster =  15                             ' hold for 1.5 seconds
   sMonster = 4                                ' update state
 ENDIF
 GOTO Main


RM_4:
 IF (tmrMonster = 0) THEN                      ' expired?
   BarrelAudio = IsOff                         ' kill audio
   tmrMonster = 300                            ' 30s reset delay
   sMonster = 5                                ' update state
 ENDIF
 GOTO Main

RM_5:
 IF (tmrMonster = 0) THEN                      ' expired?
   sMonster = 0                                ' update state
   GOTO RM_0                                   ' check new trigger
 ENDIF
 GOTO Main


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


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


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

JonnyMac

October 27, 2010, 07:05:09 AM #12 Last Edit: October 27, 2010, 07:07:17 AM by JonnyMac
QuoteIs the basic premise of the program correct?

Yes.  See my updated listing above for the complete conversion.  You may need to tweak the debounce loop in order to get to ~0.1s timing when running through the state handlers.

Remember:
-- You enter each prop handler with a state for the prop (0 is waiting for trigger, 1-N are active states)
-- User BRANCH to jump to the state handler
-- if BRANCH fails (bad state value), correct the state (set to 0) and drop through to the state 0 handler code
-- state 0 (usually) looks for the trigger activation -- it could be just a delay for auto-repeating props
-- to hold outputs, set a timer for that prop/state; decrement non-zero timer at top of program (after debounce loop)

Things can get a little hairy when you want to have a state with random events.  In this case you need to create a secondary timer -- here's an example that randomly flashes an output for 10 seconds after the trigger is detected.  As you can see, the work in state 1 is a little more involved.

Run_Flasher:
 BRANCH sFlasher, [RF_0, RF_1, RF_2]

 sFlasher = 0                                  ' fix busted state

RF_0:
 IF (trFlasher = IsOn) THEN                    ' have trigger?
   tmrFlasher = 100                            ' flash for 10 seconds
   sFlasher = 1                                ' update state
 ENDIF
 GOTO Main                                     ' next prop/process

RF_1:
 IF (tmrFlasher > 0) THEN                      ' still flashing?
   IF (flashTix = 0) THEN                      ' flash timer expired?
     Flasher = IsOn - Flasher                  ' toggle flasher pin
     RANDOM lottery
     flashTix = lottery // 5 + 1               ' set to 0.1 to 0.5 seconds
   ELSE
     flashTix = flashTix - 1
   ENDIF
 ELSE
   Flasher = IsOff                             ' ensure off
   sFlasher = 2                                ' update state
   tmrFlasher = 300                            ' reset delay, 30s
 ENDIF
 GOTO Main

RE_2:
 IF (tmrFlasher = 0) THEN                      ' expired?
   sFlasher = 0                                ' update state
   GOTO RF_0                                   ' check new trigger
 ENDIF
 GOTO Main


Jon McPhalen
EFX-TEK Hollywood Office

a94cobra


a94cobra

Thanks again.  Halloween went off without a hitch.!!!