November 23, 2024, 04:59:10 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.


Prop1 programming with RC4, CAR/P300

Started by meadowcreek, October 31, 2008, 11:06:48 AM

Previous topic - Next topic

meadowcreek

Do you have time for a little code help?

I have a PIR on 6 and an RC4 on 7 (with lights, strobe, fogger, and a wiper Motor...K1-4 respectively)
out0 & out1 are wickLEDs
out3 is attached to a trigger for the CAR/P300

I would like to have the candles going constantly...before and after the trigger.
After the trigger, start the fogger, lights, strobe and trigger the CAR/P300
wait 3 seconds and start the wiper motor
run for 8 seconds
Turn off lights, strobe, fogger, and a wiper Motor
Turn off CAR/P300
Wait 10 second delay and back to main to wait for next PIR trigger

JonnyMac

Whenever you want something "going constantly" while other processes are running you are forced to write tricky code; I think the best way to handle this is with a state machine.  Note as easy to understand at first, but S/M programs do allow us to create projects that seem to "multi-task."

' =========================================================================
'
'   File......
'   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... 31 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

SYMBOL  CARP            = PIN2
SYMBOL  Wick2           = PIN1
SYMBOL  Wick1           = PIN0

' -----[ 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   Lights         =  BIT0
SYMBOL   Strobe         =  BIT1
SYMBOL   Fogger         =  BIT2
SYMBOL   Wiper          =  BIT3

SYMBOL  state           = B2

SYMBOL  timer           = W4
SYMBOL  lottery         = W5
SYMBOL   lottoLo        =  B10
SYMBOL   lottoHi        =  B11


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

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

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

  state = 0
  timer = 0


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

Main:
  PAUSE 25                                      ' loop pad
  timer = timer + 25                            ' update process timer
  GOSUB Update_Wicks                            ' flicker candles

Run_State:
  BRANCH state, (Pgm_Delay, Wait_Trigger, Start_Audio, Delay_3, Delay_8)
  state = 0


Pgm_Delay:
  IF timer < 10000 THEN Main                    ' delay done?
    state = 1
    timer = 0
    GOTO Main


Wait_Trigger:
  timer = timer * Trigger                       ' scan input
  IF timer < 125 THEN Main                      ' wait for valid signal
    state = 2
    timer = 0
    GOTO Main


Start_Audio:
  CARP = IsOn
  Fogger = IsOn
  Lights = IsOn
  Strobe = IsOn
  GOSUB Set_RC4
  GOSUB Update_Wicks
  CARP = IsOff
  state = 3
  timer = 0
  GOTO Main


Delay_3:
  IF timer < 3000 THEN Main
    Wiper = IsOn
    GOSUB Set_RC4
    GOSUB Update_Wicks
    state = 4
    timer = 0


Delay_8:
  IF timer < 8000 THEN Main
    GOTO Reset


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

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

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

Update_Wicks:
  RANDOM lottery
  Wick1 = lottoLo
  Wick2 = lottoHi
  RETURN


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