November 04, 2024, 11:08:31 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Program Request: Chandelier controller using Prop-1 and FC-4

Started by Liam, August 24, 2008, 08:18:27 PM

Previous topic - Next topic

Liam

Hi Jon,

I am working on a chandelier prop for this year, and need a hand getting my head around the program I'm trying to write to control it.

As you may recall, you wrote some great FC-4 flicker programs for me last year. I'm trying to go the next step though, and control a solenoid also. The program would ideally go like this:

1. FC-4 will flicker chandelier lights (just one output) while idle.
2. When triggered by a PIR, the pneumatic cylinder will thrash randomly (hangman style) for five seconds while the lights continue to flicker.
3. Return to idle flickering, and wait 30 seconds until it can be triggered again.

I have tried to explain it as well as possible, but if you need more clarification please let me know.

Many thanks, as always.

Liam

JonnyMac

Give this a try.  Note that since you want constant flickering the best design strategy is what's called a finite state machine.  Luckily, PBASIC makes FSM design easy with the BRANCH statement.

In the future, please give me a name for your programs.  Thanks.

' =========================================================================
'
'   File...... Liam_Flaming_Hangman.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... 24 AUG 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Hangman         = PIN0


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  state           = B2

SYMBOL  timer           = W3

SYMBOL  flame1          = W4
SYMBOL   fire1          =  B8
SYMBOL   fire2          =  B9

SYMBOL  flame2          = W5
SYMBOL   fire3          =  B10
SYMBOL   fire4          =  B11



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

Reset:
  PINS = %00000000                              ' clear all outputs
  DIRS = %00000001                              ' make P1 an output

  flame1 = 1031                                 ' seed

  SEROUT Sio, Baud, ("!!!!!!FC4", %00, "X")     ' resync and reset


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

Main:
  RANDOM flame1
  RANDOM flame2
  SEROUT Sio, Baud, ("!FC4", %00, "S", fire1, fire2, fire3, fire4)
  timer = timer + 42

  BRANCH state, (Check_PIR, Thrash, Rest)

State_Error:
  timer = 0
  state = 0
  GOTO Main

Check_PIR:
  timer = timer * PIR                           ' scan PIR
  IF timer < 100 THEN Main                      ' valid signal
    state = 1                                   ' yes, advance state
    timer = 0                                   ' reset timer for next state
    GOTO Main

Thrash:
  Hangman = flame1                              ' thrash about
  IF timer < 5000 THEN Main                     ' for five seconds
    state = 2
    timer = 0
    GOTO Main

Rest:
  Hangman = IsOff                               ' rest
  IF timer < 30000 THEN Main                    ' for 30 seconds
    state = 0
    timer = 0
    GOTO Main


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


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


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


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

Liam

Awesome, thanks so much Jon. I was afraid that multitasking like that would require a Prop-2, but I'm very glad to learn about the BRANCH statement. I'll try this out tomorrow and let you know how it goes. Will also make a note to name my programs in the future. Thanks again!

Liam

JonnyMac

Keep in mind that there are limits as to what we can do with the Prop-1, even with the coolness of BRANCH.  Note that timer is always incremented by 42 in the Main section.  The reason for this is that's how long it takes to update all four channels of the FC-4, so that is the shortest time fragment we have here.  As it turns out, though, I think it will work pretty well for this program.
Jon McPhalen
EFX-TEK Hollywood Office

Liam

Hi again Jon,

The program worked exactly as I asked, so thank you as always for your quick and precise response. It turns out that it needs a bit of a tweak though. It turns out that the pneumatic cylinder can't keep up with the speed of the solenoid, and end up not moving very much ultimately.

So my question is - would it be possible to keep the flicker about the same as it is now, but slow down the speed at which the solenoid triggers? Ideally I think it would need to pause over half a second between triggering for the cylinder to extend and retract enough to shake the chandelier.

I'm not sure if this is possible or not given the potential limitations of the Prop-1, but if it's possible it would be much appreciated. I also do have a Prop-2 at my disposal if I'm getting too deep here.

Thanks again,
Liam

JonnyMac

No need to use a Prop-2, the Prop-1 has plenty of power for this program.  Give this version a try.  I changed the timing to 1/4 second.  Keep in mind that the solenoid is not simply toggling (that would look boring) but is being randomly pulsed based on the value of flame1.  Let me know how it goes.

' =========================================================================
'
'   File...... Liam_Flaming_Hangman.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... 26 AUG 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN
SYMBOL  Hangman         = PIN0


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  state           = B2
SYMBOL  subTimer        = B3

SYMBOL  timer           = W3

SYMBOL  flame1          = W4
SYMBOL   fire1          =  B8
SYMBOL   fire2          =  B9

SYMBOL  flame2          = W5
SYMBOL   fire3          =  B10
SYMBOL   fire4          =  B11



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

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

  flame1 = 1031                                 ' seed

  SEROUT Sio, Baud, ("!!!!!!FC4", %00, "X")     ' resync and reset


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

Main:
  RANDOM flame1
  RANDOM flame2
  SEROUT Sio, Baud, ("!FC4", %00, "S", fire1, fire2, fire3, fire4)
  timer = timer + 42

  BRANCH state, (Check_PIR, Thrash, Rest)

State_Error:
  timer = 0
  state = 0
  GOTO Main

Check_PIR:
  timer = timer * PIR                           ' scan PIR
  IF timer < 100 THEN Main                      ' valid signal
    state = 1                                   ' yes, advance state
    timer = 0                                   ' reset timer for next state
    subTimer = 0
    GOTO Main

Thrash:
  subTimer = subTimer + 1                       ' update subTimer
  IF subTimer < 6 THEN Thrash_Check             ' 1/4 second?
    Hangman = flame1                            ' yes, thrash about
    subTimer = 0                                ' reset subTimer

Thrash_Check:
  IF timer < 5000 THEN Main                     ' for five seconds
    state = 2
    timer = 0
    GOTO Main

Rest:
  Hangman = IsOff                               ' rest
  IF timer < 30000 THEN Main                    ' for 30 seconds
    state = 0
    timer = 0
    GOTO Main


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


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


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

Liam

Thanks again, Jon. I will try it out tonight if time allows and will let you know how it goes.

Liam