November 21, 2024, 05:05:53 PM

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.


Using Prop 1 for Halloween - Unable to get coding right!

Started by eboomer, October 08, 2018, 07:36:25 PM

Previous topic - Next topic

eboomer

was using a dual blaster code from two halloween's ago and apparently it does not work right the way i need it to work.
I am trying to get the prop 1 to do three things: 1) turns a motor for about 30 seconds and turns off 2) then air is blasted onto the people for 10 seconds 3) have a pop up from a barrel to stay up for about 20 seconds.  All of these of course is triggered by pir.  Am I putting too much on the prop 1 in this or can this be done?  I am just  a mainstay on the prop 1 and really like it alot.  Can someone help me or should i use different controllers for each event?

Jeff Haas

So you want one PIR to trigger three events, one after the other?  This should work fine with a single Prop-1.

Can you post the code you're currently using?

eboomer

Sorry it took so long to reply but here it is. 

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


' -----[ Program Description ]---------------------------------------------
'
' Trigger2 :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'             -- connect N.O. button between P7.W and P7.R
'
' Trigger1 :: Parallax-compatible PIR or N.O. button (mat switch, etc.)
'             -- connect N.O. button between P6.W and P6.R


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


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

SYMBOL  Trigger2        = PIN7                  ' SETUP = DN
SYMBOL  Trigger1        = PIN6                  ' SETUP = DN

SYMBOL  Valve2          = PIN1
SYMBOL  Valve1          = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  triggers        = B0
SYMBOL   tr2            =  BIT7
SYMBOL   tr1            =  BIT6

SYMBOL  idx             = B2

SYMBOL  timer2          = W3
SYMBOL  timer1          = W4
SYMBOL  lottery         = W5


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00000011                              ' set output pins


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

Main:
  triggers = %11000000                          ' arm T1 and T2 for scan
  FOR idx = 1 TO 90                             ' 450ms scan (90 x 5ms)
    RANDOM lottery
    PAUSE 5
    triggers = triggers & PINS                  ' scan inputs
  NEXT


Check_Timer1:
  IF timer1 = 0 THEN Check_Trigger1             ' timer running?
    timer1 = timer1 - 1                         ' yes, decrement
    IF timer1 > 0 THEN Check_Timer2             ' done?
      IF Valve1 = IsOff THEN Check_Timer2       ' yes, check valve
        Valve1 = IsOff                          ' turn off (if running)
        RANDOM lottery
        timer1 = lottery // 51 + 50             ' set random hold-off
        GOTO Check_Timer2

Check_Trigger1:
  IF tr1 = No THEN Check_Timer2                 ' skip if no trigger
    Valve1 = IsOn                               ' activate valve
    RANDOM lottery
    timer1 = lottery // 11 + 10                 ' set random burst


Check_Timer2:
  IF timer2 = 0 THEN Check_Trigger2             ' timer running?
    timer2 = timer2 - 1                         ' yes, decrement
    IF timer2 > 0 THEN Main                     ' done?
      IF Valve2 = IsOff THEN Main               ' yes, check valve
        Valve2 = IsOff                          ' turn off (if running)
        RANDOM lottery
        timer2 = lottery // 51 + 50             ' set random hold-off
        GOTO Main

Check_Trigger2:
  IF tr2 = No THEN Main                         ' skip if no trigger
    Valve2 = IsOn                               ' activate valve
    RANDOM lottery
    timer2 = lottery // 11 + 10                 ' set random burst
    GOTO Main


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


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


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

Thinking that I might use this for what I want it just didn't want to do what I "would" like for it to do.  Any help in this matter would be great.  Just finishing up my maze in my garage while I was trying to figure this out!  Thanks "way in advance"!!

eboomer

If there is too much coding for the one PIR to control these events, I do have at least three PIR to accomplish this separately. If that's possible and easier. 

Jeff Haas

I think I have what you asked for.  The code below is adapted from JonnyMac's examples here on the forum.  I've tested it with a PIR and the Prop-1 Trainer.

The PIR will set off the three props, one after the other.  Then there is a 20 second reset time before they can be triggered again.  If you don't have this reset, then the props will go off again as soon as the PIR sees movement.

Connect the PIR to the header on Pin 6, and move the Setup jumper so it's in the DN position.  Then connect your props to Pins 0 - 2.

If you want to change the time each prop runs, look in the Constants section for the values for "MotorRun" and so on.

' =========================================================================
'
'   File...... PIR and 3 Props
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated... 10 OCT 2018
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
' From eboomer, EFX-Tek forum
' triggered by pir:
' 1) turns on a motor for about 30 seconds and turns off
' 2) Then air is blasted onto the people for 10 seconds
' 3) have a pop up from a barrel to stay up for about 20 seconds.

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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Motor           = PIN2                  ' use P2/OUT2
SYMBOL  Air             = PIN1                  ' use P1/OUT1
SYMBOL  Barrel          = PIN0                  ' use P0/OUT0

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  TrOn            = 1                     ' active-high trigger
SYMBOL  TrOff           = 0

SYMBOL  IsOn            = 1                     ' active-high I/O
SYMBOL  IsOff           = 0

SYMBOL  Baud            = OT2400

SYMBOL  MotorRun        = 30000                 ' Change these for delay times
SYMBOL  AirRun          = 10000
SYMBOL  BarrelUp        = 20000


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

SYMBOL  timer           = B2                    ' for debounce loop


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

Power_Up:

Reset:
  PAUSE 20000                                   ' PIR warm-up time/reset after trigger

  PINS = %00000000                              ' all off
  DIRS = %00000111                              ' P2..P0 are outputs


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

Main:
  timer = 0                                     ' reset debounce timer

Check_Trigger:
  PAUSE 5                                       ' scan delay
  IF Trigger = TrOff THEN Main                  ' check trigger input
    timer = timer + 5                           ' update timer
  IF timer < 100 THEN Check_Trigger             ' check timer

Motor_Spin:

  Motor = IsOn
  PAUSE MotorRun
  Motor = IsOff

Air_Blast:

  Air = IsOn
  PAUSE AirRun
  Air = IsOff

Barrel_Popup:

  Barrel = IsOn
  PAUSE BarrelUp
  Barrel = IsOff

  GOTO Reset


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


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


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


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


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

eboomer

You are definitely a life saver!  I was letting off some nervous energy and finishing up my maze in my garage!  I am going to program this early in the morning so I can rest assured this is done!  Again thanks!