2 routines with a switch
JAMB1234
Posts: 8
Please take a look at my program and see if anyone can help please. When I switch IN0 from 1 to 0 the program will execute the next routine but not without running the previous routine one more time. Can anyone help me figure out how I can avoid running the last routine once before it goes on to the next routine.
Thanks
'{$STAMP BS2}
'{$PBASIC 2.5}
timecounterA VAR······· Word·············· ' Time Score of player A
timecounterB VAR······· Word·············· ' Time Score of Player B
DO
DO
DEBUG "PRESS BUTTONS TO STAGE" , CR
IF (IN0=1)THEN
GOTO PRO
ENDIF
IF (IN0=0)THEN
GOTO SUB
ENDIF
SUB:
DO
' Nothing
·LOOP UNTIL (IN3 = 1) AND (IN4 = 1)
HIGH 15
PAUSE 2000
HIGH 14
PAUSE 2000
HIGH 13
PAUSE 3000
HIGH 12
PAUSE 1000
LOW 15
LOW 13
LOW 14
LOW 12
HIGH 9
HIGH 10
HIGH 11
PAUSE 400
LOW 9
LOW 10
LOW 8
LOW 7
LOW 11
PAUSE 1
HIGH 8
HIGH 7
timecounterA = 0
timecounterB = 0
DO
PAUSE 1
IF (IN3 = 1) THEN
timecounterA = timecounterA + 1
ENDIF
IF (IN4 =1) THEN
timecounterB = timecounterB + 1
ENDIF
LOOP UNTIL (IN3 = 0) AND (IN4 = 0)
LOW 8
LOW 7
IF (timecounterA =0) THEN
DEBUG " Left Lane FOUL" , CR
DEBUG " Right Lane Wins" , CR, CR
HIGH 6
PAUSE 4000
LOW 6
ELSEIF (timecounterB = 0) THEN
DEBUG "· Right Lane FOUL" , CR
DEBUG·· "Left Lane Wins" , CR
HIGH 5
PAUSE 4000
LOW 5
ELSE
DEBUG "Left Lane time: ", DEC timecounterA/265,".",DEC2 timecounterA//1000,CR
DEBUG "Right Lane time: ", DEC timecounterB/265,".",DEC2 timecounterB//1000, CR, CR
IF (timecounterA < timecounterB) THEN
··· DEBUG "Left Lane is the winner!", CR
HIGH 15
PAUSE 2000
LOW 15
ELSEIF (timecounterB < timecounterA) THEN
DEBUG "Right Lane is the winner!", CR
HIGH 14
PAUSE 2000
LOW 14
ELSE
DEBUG "It's a Tie!", CR
ENDIF
DEBUG CR
DEBUG "To play again, Hold the", CR
DEBUG "BUTTONS DOWN AGAIN.",CR, CR
ENDIF
LOOP
DO
PRO:
DO
' Nothing
·LOOP UNTIL (IN3 = 1)
·HIGH 15
PAUSE 500
HIGH 14
PAUSE 500
HIGH 13
PAUSE 500
HIGH 12
PAUSE 1000
LOW 15
LOW 13
LOW 14
LOW 12
HIGH 9
HIGH 10
HIGH 11
PAUSE 400
LOW 9
LOW 10
LOW 8
LOW 7
LOW 11
PAUSE 1
HIGH 8
HIGH 7
timecounterA = 0
DO
PAUSE 1
IF (IN3 = 1) THEN
timecounterA = timecounterA + 1
ENDIF
LOOP UNTIL (IN3 = 0)
LOW 8
LOW 7
IF (timecounterA =0) THEN
DEBUG " FOUL " , CR
DEBUG " Right Lane Wins" , CR, CR
HIGH 6
PAUSE 4000
LOW 6
ELSE
DEBUG "Left Lane time: ", DEC timecounterA/260,".",DEC2 timecounterA//1000, " seconds ", CR
DEBUG "To play again, Hold the", CR
DEBUG "BUTTONS DOWN AGAIN.",CR, CR
ENDIF
LOOP
LOOP
Thanks
'{$STAMP BS2}
'{$PBASIC 2.5}
timecounterA VAR······· Word·············· ' Time Score of player A
timecounterB VAR······· Word·············· ' Time Score of Player B
DO
DO
DEBUG "PRESS BUTTONS TO STAGE" , CR
IF (IN0=1)THEN
GOTO PRO
ENDIF
IF (IN0=0)THEN
GOTO SUB
ENDIF
SUB:
DO
' Nothing
·LOOP UNTIL (IN3 = 1) AND (IN4 = 1)
HIGH 15
PAUSE 2000
HIGH 14
PAUSE 2000
HIGH 13
PAUSE 3000
HIGH 12
PAUSE 1000
LOW 15
LOW 13
LOW 14
LOW 12
HIGH 9
HIGH 10
HIGH 11
PAUSE 400
LOW 9
LOW 10
LOW 8
LOW 7
LOW 11
PAUSE 1
HIGH 8
HIGH 7
timecounterA = 0
timecounterB = 0
DO
PAUSE 1
IF (IN3 = 1) THEN
timecounterA = timecounterA + 1
ENDIF
IF (IN4 =1) THEN
timecounterB = timecounterB + 1
ENDIF
LOOP UNTIL (IN3 = 0) AND (IN4 = 0)
LOW 8
LOW 7
IF (timecounterA =0) THEN
DEBUG " Left Lane FOUL" , CR
DEBUG " Right Lane Wins" , CR, CR
HIGH 6
PAUSE 4000
LOW 6
ELSEIF (timecounterB = 0) THEN
DEBUG "· Right Lane FOUL" , CR
DEBUG·· "Left Lane Wins" , CR
HIGH 5
PAUSE 4000
LOW 5
ELSE
DEBUG "Left Lane time: ", DEC timecounterA/265,".",DEC2 timecounterA//1000,CR
DEBUG "Right Lane time: ", DEC timecounterB/265,".",DEC2 timecounterB//1000, CR, CR
IF (timecounterA < timecounterB) THEN
··· DEBUG "Left Lane is the winner!", CR
HIGH 15
PAUSE 2000
LOW 15
ELSEIF (timecounterB < timecounterA) THEN
DEBUG "Right Lane is the winner!", CR
HIGH 14
PAUSE 2000
LOW 14
ELSE
DEBUG "It's a Tie!", CR
ENDIF
DEBUG CR
DEBUG "To play again, Hold the", CR
DEBUG "BUTTONS DOWN AGAIN.",CR, CR
ENDIF
LOOP
DO
PRO:
DO
' Nothing
·LOOP UNTIL (IN3 = 1)
·HIGH 15
PAUSE 500
HIGH 14
PAUSE 500
HIGH 13
PAUSE 500
HIGH 12
PAUSE 1000
LOW 15
LOW 13
LOW 14
LOW 12
HIGH 9
HIGH 10
HIGH 11
PAUSE 400
LOW 9
LOW 10
LOW 8
LOW 7
LOW 11
PAUSE 1
HIGH 8
HIGH 7
timecounterA = 0
DO
PAUSE 1
IF (IN3 = 1) THEN
timecounterA = timecounterA + 1
ENDIF
LOOP UNTIL (IN3 = 0)
LOW 8
LOW 7
IF (timecounterA =0) THEN
DEBUG " FOUL " , CR
DEBUG " Right Lane Wins" , CR, CR
HIGH 6
PAUSE 4000
LOW 6
ELSE
DEBUG "Left Lane time: ", DEC timecounterA/260,".",DEC2 timecounterA//1000, " seconds ", CR
DEBUG "To play again, Hold the", CR
DEBUG "BUTTONS DOWN AGAIN.",CR, CR
ENDIF
LOOP
LOOP
Comments
DO
DEBUG "PRESS BUTTONS TO STAGE" , CR
IF (IN0=1)THEN
GOTO PRO
ENDIF
IF (IN0=0)THEN
GOTO SUB
ENDIF
to this
DO
DEBUG "PRESS BUTTONS TO STAGE" , CR
IF (IN0=1)THEN
GOTO PRO
ELSE
GOTO SUB
ENDIF
Thanks
You could do this
DEBUG "PRESS BUTTONS TO STAGE" , CR
IF (IN0=1)THEN
GOTO PRO
ELSEIF (IN0=0)THEN
GOTO SUB
ENDIF
·
When I switch IN0 from 1 to 0 the program will execute the next routine but not without running the previous routine one more time.
Which routine is your default routine you could have the routine setup that if it loop so many time then it will do that routine
let say that your SUB routine is the default routine unless you hit that switch
· cntr = cntr + 1 *· Chg··············· · ' Chg·is your input PIN
·IF (cntr =·300 ) THEN GOTO·SUB
· ' cntr= How many loop it will run as long as (·Input =·1 )If cntr = 300··then it will run·PRO routine any thing less than 300 is same thing as a·do nothing loop it still checking the input pin state
This routine dose the same thing except it dose this
·' cntr= How many loop it will run as long as (·Input =·0 )·If cntr = 300 then it will run SUB routine any thing less than 300 is same thing as a·do nothing loop it still checking the input pin state
·DO
··· cntr = cntr + 1 * (1 - Chg)
··· IF (cntr = 300) THEN·GOTO PRO
·· I hope this help································· ·cntr can be any value
This an example of how you would this ___________________________________________________________________
·chg············ PIN···· 4
cntr··········· VAR···· Word
DO
·· cntr = cntr + 1 *· Chg·············'If input = 1 and·CNTR get·to a·count of 300
····· IF (cntr = 300 ) THEN·········· 'then it become true
······ GOTO· sub
·· cntr = cntr + 1 * (1 - Chg)····· 'If input =·0 and·CNTR get·to a·count of 300·
··· IF (cntr = 300) THEN···············'then it become true
······ GOTO· PRO
······ ENDIF
······ ENDIF
·····
·····
·LOOP
·Sub:
·HIGH 1
·PAUSE 500
·LOW 1
·RETURN
·PRO:
·HIGH 2
·PAUSE 500
·LOW 2
·RETURN
··___________________________________________________________________________________________
· DO
DO
DEBUG "PRESS BUTTONS TO STAGE" , CR
IF (IN0=1)THEN
GOTO PRO
ENDIF
IF (IN0=0)THEN
GOTO SUB
ENDIF
One problem that I see is that you have two DO and from what·I can see you are looping your hole routine
This make it hard to follow
One more thing it hard to follow your routine with all output pins not defined
LOW 15
LOW 13
LOW 14
LOW 12
HIGH 9
HIGH 10
HIGH 11
··Name ·Pin 15
· Name· Pin 14
· Name· Pin·13
· Name··Pin 12
and so on
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 10/19/2008 2:26:57 AM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering