What is a command to skip part of a loop?
Radiohead
Posts: 3
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
'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
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.
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..
So goes for the people on this Forum!
Welcome, Radiohead!
Does that make the others are usurp-friendly?
You can post code in a way that keeps the formatting, within a code block...