November 23, 2024, 04:21:07 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.


Quick Help!

Started by mortiseman, October 26, 2009, 08:47:23 PM

Previous topic - Next topic

mortiseman

Good Evening,

Last year you helped me write a program for a prop that I have. I would like to modify it a little bit this year and am having a heck of a time getting it to work. Basically it is the same program however, I would like the pop-up to shake a bit via the valve before it pops up. Below is the code that you wrote last year...

Like I said, everything works great I would just like to add a "shake" before the Valve_On.

Thanks so much for your help!!!!

' =========================================================================
'
'   File...... Mortiseman.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... 09 OCT 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN (PIR)
SYMBOL  Eyes            = 5                     ' P5 (servo)
SYMBOL  Neck            = 4                     ' P4 (servo)
SYMBOL  WickLed         = PIN1                  ' OUT1
SYMBOL  Valve           = PIN0                  ' OUT0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  state           = B0                    ' program state
SYMBOL  pirTimer        = B1                    ' debounce for PIR

SYMBOL  eyesPos         = B2
SYMBOL  eyesTarget      = B3
SYMBOL  eyeSpeed        = B4

SYMBOL  neckPos         = B5
SYMBOL  neckTarget      = B6

SYMBOL  timer           = W4                    ' show timer
SYMBOL  lottery         = W5                    ' random #


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

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

  eyesPos = 100                                 ' one side
  eyesTarget = 200                              ' other side

  neckPos = 100                                 ' rest position

  state = 0


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

Main:
  RANDOM lottery
  PULSOUT Eyes, eyesPos
  PULSOUT Neck, neckPos
  PAUSE 11                                      ' pad for ~20 ms

  IF timer = 0 THEN Check_Eyes                  ' skip if expired
    timer = timer - 1                           '  update timer


' ------------------
' Update moving eyes
' ------------------

Check_Eyes:
  IF state <> 0 THEN Check_Wick                 ' don't move when active

  eyeSpeed = eyeSpeed + 1                       ' update speed divider
  IF eyeSpeed < 2 THEN Check_Wick               ' check
    eyeSpeed = 0                                ' reset speed control

  IF eyesPos <> eyesTarget THEN Move_Eyes       ' at target?
    IF eyesPos = 200 THEN Target_100            '  yes, check side
      eyesTarget = 200
      GOTO Run_State

Target_100:
  eyesTarget = 100
  GOTO Run_State

Move_Eyes:
  IF eyesPos > eyesTarget THEN Move_Back
    eyesPos = eyesPos + 1
    GOTO Run_State

Move_Back:
  eyesPos = eyesPos - 1
  GOTO Run_State


' ---------------
' Update WickLeds
' ---------------

Check_Wick:
  WickLed = IsOff                               ' assume off
  IF state < 3 THEN Run_State                   ' abort if yes
    WickLed = lottery                           ' else use random bit


' ---------------------
' Process program state
' ---------------------

Run_State:
  IF state = 0 THEN Check_PIR
  IF state = 1 THEN Neck_To
  IF state = 2 THEN Head_Delay
  IF state = 3 THEN Valve_On
  IF state = 4 THEN Neck_Back

  state = 0


Check_PIR:
  pirTimer = pirTimer + 20 * Trigger
  IF pirTimer < 100 THEN Main
    state = 1
    eyesPos = 150                               ' center eyes
    neckTarget = 200                            ' turn neck
    GOTO Main


Neck_To:                                        ' takes about 1 sec
  neckPos = neckPos + 2
  IF neckPos <> neckTarget THEN Main
    state = 2
    timer = 9000 / 20                           ' delay 9 secs
    GOTO Main


Head_Delay:
  IF timer > 0 THEN Main
    state = 3
    Valve = IsOn
    timer = 10000 / 20                          ' on for 10 secs
    GOTO Main


Valve_On:
  IF timer > 0 THEN Main
    state = 4
    Valve = IsOff
    neckTarget = 100
    GOTO Main


Neck_Back:
  neckPos = neckPos - 2
  IF neckPos <> neckTarget THEN Main
    state = 0
    pirTimer = 0
    GOTO Main


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


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

JonnyMac

Okay, define "shake."  With the valve?  And for how long before we activate the valve.
Jon McPhalen
EFX-TEK Hollywood Office

mortiseman

Last year I had the prop in a garbage can (trash can terror). This year I made a wooden crate with a lid on a hinge. I just want it to slam the lid 3 or 4 times before it pop's up.  Right now the valve justs opens one time then closes. I would like a few short burts before it opens all the way....

Does that help?

mortiseman

It is using the "Pneumatic Pop-Up Kit" from MonsterGuts.com if that helps. 18" stroke.

Thanks again!!

JonnyMac

This program is definitely in the "advanced" camp.  Give this update a try. 

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


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN (PIR)
SYMBOL  Eyes            = 5                     ' P5 (servo)
SYMBOL  Neck            = 4                     ' P4 (servo)
SYMBOL  WickLed         = PIN1                  ' OUT1
SYMBOL  Valve           = PIN0                  ' OUT0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  state           = B0                    ' program state
SYMBOL  pirTimer        = B1                    ' debounce for PIR

SYMBOL  eyesPos         = B2
SYMBOL  eyesTarget      = B3
SYMBOL  eyeSpeed        = B4

SYMBOL  neckPos         = B5
SYMBOL  neckTarget      = B6

SYMBOL  bumps           = B7

SYMBOL  timer           = W4                    ' show timer
SYMBOL  lottery         = W5                    ' random #


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

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

  eyesPos = 100                                 ' one side
  eyesTarget = 200                              ' other side

  neckPos = 100                                 ' rest position

  state = 0


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

Main:
  RANDOM lottery
  PULSOUT Eyes, eyesPos
  PULSOUT Neck, neckPos
  PAUSE 11                                      ' pad for ~20 ms

  IF timer = 0 THEN Check_Eyes                  ' skip if expired
    timer = timer - 1                           '  update timer


' ------------------
' Update moving eyes
' ------------------

Check_Eyes:
  IF state <> 0 THEN Check_Wick                 ' don't move when active

  eyeSpeed = eyeSpeed + 1                       ' update speed divider
  IF eyeSpeed < 2 THEN Check_Wick               ' check
    eyeSpeed = 0                                ' reset speed control

  IF eyesPos <> eyesTarget THEN Move_Eyes       ' at target?
    IF eyesPos = 200 THEN Target_100            '  yes, check side
      eyesTarget = 200
      GOTO Run_State

Target_100:
  eyesTarget = 100
  GOTO Run_State

Move_Eyes:
  IF eyesPos > eyesTarget THEN Move_Back
    eyesPos = eyesPos + 1
    GOTO Run_State

Move_Back:
  eyesPos = eyesPos - 1
  GOTO Run_State


' ---------------
' Update WickLeds
' ---------------

Check_Wick:
  WickLed = IsOff                               ' assume off
  IF state < 4 THEN Run_State                   ' abort if yes
    WickLed = lottery                           ' else use random bit


' ---------------------
' Process program state
' ---------------------

Run_State:
  IF state = 0 THEN Check_PIR
  IF state = 1 THEN Neck_To
  IF state = 2 THEN Head_Delay
  IF state = 3 THEN Shake_It
  IF state = 4 THEN Valve_On
  IF state = 5 THEN Neck_Back

  state = 0


Check_PIR:
  pirTimer = pirTimer + 20 * Trigger
  IF pirTimer < 100 THEN Main
    state = 1
    eyesPos = 150                               ' center eyes
    neckTarget = 200                            ' turn neck
    GOTO Main


Neck_To:                                        ' takes about 1 sec
  neckPos = neckPos + 2
  IF neckPos <> neckTarget THEN Main
    state = 2
    timer = 9000 / 20                           ' delay 9 secs
    GOTO Main


Head_Delay:
  IF timer > 0 THEN Main
    state = 3
    RANDOM lottery
    bumps = lottery // 5 + 4                    ' 4 to 8 (half cycles)
    RANDOM lottery
    timer = lottery // 11 + 5                   ' 0.1 to 0.3s
    Valve = IsOn


Shake_It:
  IF timer > 0 THEN Main
    IF bumps = 0 THEN Shake_Done
      bumps = bumps - 1
      timer = lottery // 11 + 5                 ' 0.1 to 0.3s
      Valve = 1 - Valve                         ' toggle valve state
      GOTO Main

Shake_Done:
    state = 4
    Valve = IsOn
    timer = 10000 / 20                          ' on for 10 secs
    GOTO Main


Valve_On:
  IF timer > 0 THEN Main
    state = 5
    Valve = IsOff
    neckTarget = 100
    GOTO Main


Neck_Back:
  neckPos = neckPos - 2
  IF neckPos <> neckTarget THEN Main
    state = 0
    pirTimer = 0
    GOTO Main


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


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