November 21, 2024, 10:20:52 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.


Triggered Candles.BS1 program

Started by TheChambersOfHorror, July 28, 2013, 12:11:08 PM

Previous topic - Next topic

TheChambersOfHorror

I am looking to setup my prop1 to run a program which controls faux candles. Which is easy enough :), but I need to have the candle program always run, add a trigger on("PressurePad"), a trigger off("RatTrigger") and two relays("Lights" & "Rats") ???, can you help?

I plan on using 4 of the OUTx for the candles.
I want to hook up 4 candles to each of the 4 OUTx for a total of 16.
One set of 4 candles (1 each of the 4 OUTx) will be hooked up to a "Lights" relay (through V+)
Here is the sequence;

Candle program running
Watch for "PressurePad" trigger to be made, then turn on "Lights" relay.

Then watch for "RatTrigger" to be made.
Once "RatTrigger" is tripped, turn "Lights" off and turn on "Rats" relay for 4 seconds then turn off.

Start over.

Thanks,
Ed

JonnyMac

That's going to be a tricky program but I can do it. Let me get some lunch first.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Here you go. This is somewhat tricky, requiring a state machine to execute the way you want. You may want to fine-tune the rats timing line (marked).

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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


SYMBOL  RatTrigger      = PIN7                  ' input (SETUP = DN)
SYMBOL  PresPad         = PIN6                  ' input (SETUP = DN)

SYMBOL  Rats            = PIN5                  ' output
SYMBOL  Lights          = PIN4                  ' output

SYMBOL  Wick3           = PIN3                  ' output
SYMBOL  Wick2           = PIN2                  ' output
SYMBOL  Wick1           = PIN1                  ' output
SYMBOL  Wick0           = PIN0                  ' output


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

SYMBOL  YES             = 1
SYMBOL  NO              = 0

SYMBOL  TR_ON           = 1                     ' active-high trigger
SYMBOL  TR_OFF          = 0

SYMBOL  IS_ON           = 1                     ' active-high I/O
SYMBOL  IS_OFF          = 0


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

SYMBOL  state           = B2
SYMBOL  wixbits         = B3
SYMBOL  wixdelay        = B4

SYMBOL  timer           = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' all off
  DIRS = %00111111                              ' P5..P0 are outputs

  lottery = 1031


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

Main:
  PAUSE 5                                       ' set loop speed
  RANDOM lottery                                ' big stir
  RANDOM lottery
  RANDOM lottery

Check_Wicks:
  IF wixdelay = 0 THEN Update_Wicks             ' ready for update?
    wixdelay = wixdelay - 1                     ' not yet, decrement
    GOTO Run_State

Update_Wicks:
  wixbits = lottery & $0F                       ' get new wicks pattern
  PINS = PINS & $F0 | wixbits                   ' update wick outputs
  RANDOM lottery                                ' re-stir
  wixdelay = lottery // 11 + 5                  ' new wicks delay (5 - 15)

Run_State:
  BRANCH state, (Check_Pad, Check_Rat, Run_Rats)

Check_Pad:
  timer = timer + 5 * PresPad                   ' check pad
  IF timer < 100 THEN Main                      ' valid input?
    Lights = IS_ON                              '  yes, turn lights on
    timer = 0                                   '  reset timer for next
    state = 1                                   '  update state
    GOTO Main

Check_Rat:
  timer = timer + 5 * RatTrigger
  IF timer < 100 THEN Main
    Lights = IS_OFF
    Rats = IS_ON
    timer = 0
    state = 2
    GOTO Main

Run_Rats:
  timer = timer + 5
  IF timer < 3000 THEN Main                     ' *** adjust as needed
    Rats = IS_OFF
    state = 0
    GOTO Main


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


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


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


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


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

TheChambersOfHorror

First of all, thanks for the quick response. I almost have the controls package done for the triggered candles, I have just a couple more questions. Should I replace the ULN2803A with the ULN2003A? What about the P6 trigger? Do I need to modify the ULN2003A for the P6? I hope to have it hooked up and running by Monday night.

Thanks

JonnyMac

You do not need to modify the ULN for this project as P6 and P7 are being used as simple triggers. Do check the SETUP jumpers and make sure they're in the down (DN) position.
Jon McPhalen
EFX-TEK Hollywood Office

TheChambersOfHorror

Thanks a lot! I should have it hooked up tonight. Can't wait to test it.