New to programming and need a little help.
Sparda
Posts: 5
I'm trying to get this program to cycle through each subroutine, but I can't figure out what I'm doing wrong. Any advice?
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
'
[noparse][[/noparse] Variables ]
counter VAR Nib ' Counts alternate contacts.
old15 VAR Bit ' Stores previous IN15.
old0 VAR Bit ' Stores previous IN0.
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000
counter = 1 ' Start alternate count.
old15 = 0 ' Make up old values.
old0 = 1
'
[noparse][[/noparse] Main Routine ]
DO
IF (IN15 <> IN0) THEN
IF (old15 <> IN15) AND (old0 <> IN0) THEN
counter = counter + 1
old15 = IN15
old0 = IN0
IF (counter > 4) THEN
counter = 1
GOSUB Stay_Still
ENDIF
ELSE
counter = 1
ENDIF
ENDIF
IF (IN0 = 0) AND (IN15 = 0) THEN
GOSUB Stay_Still
GOSUB Forward_Pulse
GOSUB Turn_Right
GOSUB Forward_Pulse
GOSUB Stay_Still
GOSUB Turn_Around
ELSEIF (IN0 = 0) AND (IN15 = 1) THEN
GOSUB Turn_Circle
GOSUB Stay_Still
ELSEIF (IN15 = 0) THEN
GOSUB Photoresistors
ELSE
GOSUB Stay_Still
ENDIF
LOOP
'
[noparse][[/noparse] Subroutines ]
Stay_Still:
FOR counter = 1 TO 20
PULSOUT 12, 750
PAUSE 20
NEXT
Forward_Pulse:
FOR counter = 1 TO 389
PULSOUT 13, 890
PULSOUT 12, 625
PAUSE 20
NEXT
RETURN
Turn_Around:
FOR counter = 1 TO 87
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Turn_Circle:
FOR counter = 1 TO 1250
PULSOUT 13, 850
PULSOUT 12, 717
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR counter = 1 TO 42
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Photoresistors:
IF (IN14 = 0) AND (IN1 = 0) THEN
PULSOUT 12, 750
ELSEIF (IN14 = 0) AND (IN1 = 1) THEN
HIGH 8
LOW 7
PAUSE 20
RETURN
ELSEIF (IN1 = 0) AND (IN14 = 1) THEN
HIGH 7
LOW 8
PAUSE 20
RETURN
ELSE
LOW 7
LOW 8
ENDIF
RETURN
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
'
[noparse][[/noparse] Variables ]
counter VAR Nib ' Counts alternate contacts.
old15 VAR Bit ' Stores previous IN15.
old0 VAR Bit ' Stores previous IN0.
'
[noparse][[/noparse] Initialization ]
FREQOUT 4, 2000, 3000
counter = 1 ' Start alternate count.
old15 = 0 ' Make up old values.
old0 = 1
'
[noparse][[/noparse] Main Routine ]
DO
IF (IN15 <> IN0) THEN
IF (old15 <> IN15) AND (old0 <> IN0) THEN
counter = counter + 1
old15 = IN15
old0 = IN0
IF (counter > 4) THEN
counter = 1
GOSUB Stay_Still
ENDIF
ELSE
counter = 1
ENDIF
ENDIF
IF (IN0 = 0) AND (IN15 = 0) THEN
GOSUB Stay_Still
GOSUB Forward_Pulse
GOSUB Turn_Right
GOSUB Forward_Pulse
GOSUB Stay_Still
GOSUB Turn_Around
ELSEIF (IN0 = 0) AND (IN15 = 1) THEN
GOSUB Turn_Circle
GOSUB Stay_Still
ELSEIF (IN15 = 0) THEN
GOSUB Photoresistors
ELSE
GOSUB Stay_Still
ENDIF
LOOP
'
[noparse][[/noparse] Subroutines ]
Stay_Still:
FOR counter = 1 TO 20
PULSOUT 12, 750
PAUSE 20
NEXT
Forward_Pulse:
FOR counter = 1 TO 389
PULSOUT 13, 890
PULSOUT 12, 625
PAUSE 20
NEXT
RETURN
Turn_Around:
FOR counter = 1 TO 87
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Turn_Circle:
FOR counter = 1 TO 1250
PULSOUT 13, 850
PULSOUT 12, 717
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR counter = 1 TO 42
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Photoresistors:
IF (IN14 = 0) AND (IN1 = 0) THEN
PULSOUT 12, 750
ELSEIF (IN14 = 0) AND (IN1 = 1) THEN
HIGH 8
LOW 7
PAUSE 20
RETURN
ELSEIF (IN1 = 0) AND (IN14 = 1) THEN
HIGH 7
LOW 8
PAUSE 20
RETURN
ELSE
LOW 7
LOW 8
ENDIF
RETURN
Comments
Jeff T.
Jeff T.
I wasn't asking what you intend the program to do. I was prodding you to find out what's actually happening. That's how you debug. You find out by "direct evidence" (if you can) what is actually happening and you compare that to what you think should be happening to figure out either the error in your logic or some mistake in implementing what you thought you were doing or ... whatever.
Oh, the program isn't responding at all and I haven't tried those yet.
Post Edited (Sparda) : 11/5/2007 3:57:42 PM GMT