May 19, 2024, 06:01:46 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.


how to use GOSUB?

Started by reddragon, March 14, 2009, 04:29:04 PM

Previous topic - Next topic

reddragon

Jon i have been doing some reading on the forms andtamplets so.  i am whating to have four LED's turn on and stay on for 3Min's but at the same time. That they are on i would like to have two relays on and then turn off after 6Min's. I was thinking i could use GOSUB and the examples that i see is using  timer setup of cource I'm no shure if im right because i know that people have used GOTO  I'm not shure witch one to use. :-\
     main:
      trigger
         four LED's on
           timer 3 Min's
          at the same time
              relay 1&2 come on
               timer 6 Min's
               GOTO main

JonnyMac

You can only run one timer so the three minutes you run you LEDs has to be subtracted from the six minute timing of the relays.  The process is like this:

  Wait for trigger
  Leds & Relays are on
  Hold 3 minutes
  Leds off
  Hold 3 minutes
  Relays off

Here's one way to write the program:

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


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


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


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

SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  Relay2          = PIN5
SYMBOL  Relay1          = PIN4

SYMBOL  Led4            = PIN3
SYMBOL  Led3            = PIN2
SYMBOL  Led2            = PIN1
SYMBOL  Led1            = PIN0


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  timer           = B2


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

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


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

  PINS = %00111111                              ' Leds & Relays on
  timer = 180                                   ' 180 seconds = 3 minutes
  GOSUB Delay_Secs
  PINS = %00110000                              ' Leds off, Relays stay on
  timer = 180
  GOSUB Delay_Secs

  GOTO Reset                                    ' all off


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

' Put seconds to delay in "timer" before calling

Delay_Secs:
  IF timer = 0 THEN Delay_Done
    PAUSE 1000
    timer = timer - 1
    GOTO Delay_Secs

Delay_Done:
  RETURN

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


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


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

reddragon

 Thanks Jon, hat will work- :D is there a way to run two differnt codes useing tw differnet IF THEN codes i have ordered a prop two if that can be done on a prop 2 how wold i o about starting the code would it be the same as this code?

JonnyMac

You'll have to be more specific -- and if your question is different than this thread then start a new thread, please.  I'm going to start coming down harshly on those that violate this simple rule as it makes forums almost useless if threads are by user instead of by topic.
Jon McPhalen
EFX-TEK Hollywood Office

reddragon

ok i understand . what i was saying was can i run two codes in on useing IF THEN states too devied the codes or can you use a GOTO state ok lets say

#1- If trigger is off then ( lights on ) code 1


#2- If trigger is on then ( strobe on, smoke on ) code 2

and if it can't be done on a prop1 can it be done on a prop2 sine the prop2 is abel to prosses faster? :)

JonnyMac

Thread is locked as it seems to violate our "single topic" guideline.
Jon McPhalen
EFX-TEK Hollywood Office