November 22, 2024, 08:31:19 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


constant task

Started by tj, October 04, 2008, 06:02:42 PM

Previous topic - Next topic

tj

hey jon.

i had you help me with a loop before trigger once before, but now im trying to run a fogger for 2 sec every 30 sec while waiting on random trigger ( matswitch ) i tried using a counter thinking i could change counter value for timing. this is what tried.


' =========================================================================
'
'   File......
'   Purpose...
'   Author.... pieces from many of jons and a little of mine
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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



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


' -----[ I/O Definitions ]-------------------------------------------------
  SYMBOL  Sio     = PIN7

  SYMBOL  Trigger = PIN6            ' setup dn

  SYMBOL  Led1  =   PIN0

  SYMBOL  Smoke   =   PIN3

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


  SYMBOL   IsOn = 1

  SYMBOL   IsOff = 0

  SYMBOL   Baud  = OT2400

' -----[ Variables ]-------------------------------------------------------
  SYMBOL  victim          = B2

  SYMBOL  counter         = B3

  SYMBOL  timer           = W4

  SYMBOL  lottery         = W5

  SYMBOL   FOGcounter  = B1


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

Reset:

  victim = lottery // 8 + 5                     ' 5 to 12

  counter = 0

  PINS  =  %00000000

  DIRS  =  %00010101

  FOGcounter = 0

  timer = 0

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

Main:

timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.2 sec input
    PAUSE 1000                                  ' let victim step off
    counter = counter + 1
    IF counter < victim THEN fogger               ' wait for victim count


light:

  led1 = ison

  PAUSE 1000

  led1 = isoff

  PAUSE 50

  GOTO reset

fogger:

  FOGcounter = FOGcounter + 1

  IF FOGcounter < 100 THEN main


fogfill:

  smoke = ison

  PAUSE 500

  smoke = isoff

  GOTO reset

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


JonnyMac

This is not trivial -- you need to tell me the how you want the who program to work.  It's going to require a state-machine design that is not easy to follow; so... you tell me what you want and I'll write it.
Jon McPhalen
EFX-TEK Hollywood Office

tj

ok  i want for a fog machine to run for 2sec every 30 sec on 0ut 0, while waiting for a random trigger(5-10) (mat switch) on p6.

when triggered, the fog can cut off until reset or continue its loop whatever is easiest . i need out 1 (spot), out 2 (cyl) and out 3 (spray)

to come on.

if "possible"  spot and cyl on for .5 sec before spray.  i want it to spray for  2 sec and after 10 sec  spot and cyl off

reset

JonnyMac

October 04, 2008, 11:15:14 PM #3 Last Edit: October 04, 2008, 11:17:45 PM by JonnyMac
You asked for it.... Let me warn you: this is not a beginner's program.  It works the way you ask -- it is, essentially, a multi-tasking program (albeit a slow one).  The fogger runs as one process and the trigger and show elements run as another; the only thing they have in common is base timing of 20 millisecond units.

Study this carefully before you make any changes.

' =========================================================================
'
'   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... 04 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  Spray           = PIN3
SYMBOL  Cylinder        = PIN2
SYMBOL  Spot            = PIN1
SYMBOL  Fogger          = PIN0


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  state           = B0
SYMBOL  debounce        = B1                    ' debounce timer

SYMBOL  victims         = B2

SYMBOL  fogTimer        = W3                    ' fogger timer
SYMBOL  timer           = W4                    ' state timer
SYMBOL  lottery         = W5                    ' random #


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

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

  victims = 5                                   ' set for first time


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

Main:
  RANDOM lottery                                ' stir random #
  PAUSE 20                                      ' loop pad


Check_State_Timer:
  IF timer = 0 THEN Check_Fog_Timer             ' skip if expired
    timer = timer - 1                           ' update state timer


Check_Fog_Timer:
  IF fogTimer = 0 THEN Set_Fog_Timer            ' update fogger if expired
    fogTimer = fogTimer - 1                     ' update fogger timer
    GOTO Run_State                              ' run program state


Set_Fog_Timer:
  Fogger = 1 - Fogger                           ' toggle state
  fogTimer = 100                                ' 100 x 20ms = 2 sec
  IF Fogger = IsOn THEN Run_State               ' if on, we're good
    fogTimer = 1500                             '  else set to 30 secs


Run_State:
  BRANCH state, (Check_Trigger, Release, Show_1, Show_2, Show_3)
  state = 0


Check_Trigger:
  debounce = debounce + 20 * Trigger            ' update debounce timer
  IF debounce < 100 THEN Main                   ' exit if not valid
    victims = victims - 1                       ' update victims count
    state = 1                                   ' set for release
    IF victims > 0 THEN Main
      state = 2                                 ' final victim, run show
      Spot = IsOn
      Cylinder = IsOn
      timer = 25                                ' 25 x 20ms = 0.5 secs
      GOTO Main


Release:
  IF Trigger = IsOn THEN Main                   ' wait for release
    debounce = 0                                ' reset input timer
    state = 0                                   ' back to trigger check
    GOTO Main


Show_1:                                         ' spot + cylinder timing
  IF timer > 0 THEN Main
    state = 3
    Spray = IsOn
    timer = 100                                 ' 100 x 20ms = 2 secs
    GOTO Main


Show_2:                                         ' spray timing
  IF timer > 0 THEN Main
    state = 4
    Spray = IsOff
    timer = 500                                 ' 500 x 20ms = 10 secs
    GOTO Main


Show_3:                                         ' finish timing
  IF timer > 0 THEN Main
    debounce = 0                                ' reset trigger timer
    state = 0                                   ' back to trigger check
    Cylinder = IsOff                            ' clear outputs
    Spot = IsOff
    victims = lottery // 6 + 5                  ' randomize, 5 to 10
    GOTO Main


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


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


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

tj

works perfect, i studied and figured out how to change the times on each thing using the 20ms loop timing.

i like the branch method. it seems very useful. i don't understand every aspesct but get the idea. thanks again