Shop OBEX P1 Docs P2 Docs Learn Events
What is a command to skip part of a loop? — Parallax Forums

What is a command to skip part of a loop?

RadioheadRadiohead Posts: 3
edited 2012-11-16 09:15 in BASIC Stamp
I have written a program that will control devices when a small control voltage is applied to input pin 10. The program works fine but will continue to loop and click the relays every 30 seconds or so. Is there a way to either skip the middle part of the program loop or put it into a wait state until the input voltage on pin 10 goes low? The code is below. I am new at this and this is my first program, but I do not yet know all the programming language. Could someone with experience please help>

'Control Voltage Camera interface.bs2
'GPS Interface with DVR and camera system in a GeoZone.
'{$STAMP BS2}
'{$PBASIC 2.5}
DEBUG "........GPS INTERFACE..........DVR CONTROLLER VIA GEOZONE DETECTION........"
DO
DEBUG ? IN10
IF (IN10 = 1) THEN
HIGH 4 'Activates RLY1: Applies 12VDC to the camera
DEBUG ". . .C A M E R A S O N . . . . . Y E L L O W L E D . . . . . ."
HIGH 1 'Activates RLY2:Applies 5VDC to the DVR
DEBUG ". . D V R O N - G R E E N L E D . . D V R O N . . . D V R O N . . "
PAUSE 20000
DEBUG ? IN1 'Detects if Pin 1 is high
IF (IN1 = 1) THEN
HIGH 2 'Pushes the DVR Record button
DEBUG ". . . D V R R E C O R D B U T T O N P U S H E D . . . . . . . . . . "
PAUSE 2000 'Waits 2 seconds
LOW 2 'Lets go of the DVR Record button
PAUSE 3000 'Waits an additional 3 seconds
ENDIF
ELSE
HIGH 3 'Pushes the DVR STOP button
PAUSE 2000 'Waits two seconds
LOW 3 'Lets go of the DVR Stop switch
DEBUG ". . . D V R S T O P R E C O R D . . . D V R S T O P R E C O R D . . ."
PAUSE 15000 'Waits 15 seconds to allow DVR to write video files
LOW 1 'Removes 5VDC from DVR
DEBUG ". . . D V R P O W E R O F F . . . D V R P O W E R O F F . . ."
PAUSE 2000
DEBUG ". . . C A M E R A P W R O F F . . . C A M E R A P W R O F F . . ."
LOW 4 'Removes 12VDC from the camera
ENDIF
LOOP

Comments

  • ercoerco Posts: 20,256
    edited 2012-11-15 09:28
    "GOTO abc" will jump ahead to some label named abc:

    or if you want to sit tight until pin 10 goes low, try this:

    "waithere: if in10=1 then waithere" which tests pin 10. If it's high, it loops back to itself (label waithere) and tests again. As soon as pin 10 goes low, the condition is false and it will simply continue to the next statement afterward.
  • RadioheadRadiohead Posts: 3
    edited 2012-11-15 09:32
    thank you for the quick reply, I appreciate it. I will test it promptly.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2012-11-15 10:18
    If you're in a DO...LOOP and want to exit it on a conditional you can use the EXIT keyword. See the BASIC Stamp manual or help files for more information on this command.
  • RadioheadRadiohead Posts: 3
    edited 2012-11-16 07:34
    I tried using the exit loop function but the program stops working as it exits the loop and will not detect pin 10 going low because the loop will not continue. I am going to try the wait here path to see if that works. I hope this would be a solution.

    I must say that I have worked with the Freescale Tower, Arduino and BS2. The BS2 is very user friendly and I prefer it over the others..
  • davejamesdavejames Posts: 4,047
    edited 2012-11-16 07:49
    Radiohead wrote: »
    The BS2 is very user friendly and I prefer it over the others..

    So goes for the people on this Forum!

    Welcome, Radiohead!
  • ercoerco Posts: 20,256
    edited 2012-11-16 08:27
    Radiohead wrote: »
    The BS2 is very user friendly and I prefer it over the others..

    Does that make the others are usurp-friendly?
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2012-11-16 09:15
    It can help us, and yourself, if you write out what you want to happen in outline form, properly indented. Your program is nicely commented! I'm wondering if you need to detect a change in state of IN10 or IN1 during the PAUSE intervals. If so, you will need to turn the PAUSEs into loops that periodically check the inputs.
    DO
      IF (IN10 = 1) THEN
        ' turn on camera 12V power relay1
        ' turn on DVR 5V relay
        ' wait 20 seconds
        IF (IN1 = 1) THEN
          ' Push the DVR Record button
          ' delay 2 seconds
          ' Let go of the DVR Record button
          ' wait additional 3 seconds
        ENDIF
      ELSE
        ' Push the DVR STOP button
        ' Wait two seconds
        ' Let go of the DVR Stop switch
        ' Wait 15 seconds to allow DVR to write video files
        ' Remove 5VDC from DVR
        ' wait 2 seconds
        ' Remove 12VDC from the camera
      ENDIF
    LOOP 
    


    You can post code in a way that keeps the formatting, within a code block...
    attachment.php?attachmentid=78421&d=1297987572
Sign In or Register to comment.