Dave45
01-11-2006, 09:40 AM
When I run the program in the book to have the Led's light up when a whisker touches it starts the program at the beginning as soon as a whisker touches something. Running the whiskers without the Led code works right. The only way I could get it to work was to enter the Led code after the gosub commands. When I entered it as the book show's it, it restarts the program. Wiring has been triple checked, it's right. Any ideas why when the code to light the Led's is first it restarts? Program that works is below.
'Robotics with the Boe-Bot - RoamingWithWhiskersAndLeds.bs2
'Boe-Bot uses whiskers to detect objects, and navigates around them.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
pulsecount······ VAR··· Byte·········· 'For...Next loop counter.
FREQOUT 4, 2000, 3000
DO
· IF (IN5 = 0) AND (IN7 = 0) THEN····· 'Both whiskers detect obstacles
··· GOSUB back_up····················· 'Back up and U-turn (Left twice)
··· GOSUB turn_left
··· GOSUB turn_left
··· HIGH 10
··· HIGH 1
· ELSEIF (IN5 = 0) THEN··············· 'Left whisker contacts
··· GOSUB back_up····················· 'Back up and turn right
··· GOSUB turn_right
··· HIGH 10
· ELSEIF (IN7 = 0) THEN··············· 'Right whisker contacts
··· GOSUB back_up····················· 'Back up and turn left
··· GOSUB turn_left
··· HIGH 1
· ELSE································ 'Both whiskers 1, no contacts
··· LOW 10
··· LOW 1
··· GOSUB forward_pulse··············· 'Apply a forward pulse
· ENDIF······························· 'and check again
LOOP
forward_pulse:························ 'Send a single pulse forward.
·· PULSOUT 13, 850
·· PULSOUT 12, 680
·· PAUSE 20
· RETURN
turn_left:···························· 'Left turn, about 90-degrees
· FOR pulsecount = 0 TO 20
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
turn_right:··························· 'Right turn, about 90-degrees
· FOR pulsecount = 0 TO 20
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
back_up:······························ 'Back up
· FOR pulsecount = 0 TO 40
··· PULSOUT 13, 650
··· PULSOUT 12, 820
··· PAUSE 20
· NEXT
· RETURN
'Robotics with the Boe-Bot - RoamingWithWhiskersAndLeds.bs2
'Boe-Bot uses whiskers to detect objects, and navigates around them.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
pulsecount······ VAR··· Byte·········· 'For...Next loop counter.
FREQOUT 4, 2000, 3000
DO
· IF (IN5 = 0) AND (IN7 = 0) THEN····· 'Both whiskers detect obstacles
··· GOSUB back_up····················· 'Back up and U-turn (Left twice)
··· GOSUB turn_left
··· GOSUB turn_left
··· HIGH 10
··· HIGH 1
· ELSEIF (IN5 = 0) THEN··············· 'Left whisker contacts
··· GOSUB back_up····················· 'Back up and turn right
··· GOSUB turn_right
··· HIGH 10
· ELSEIF (IN7 = 0) THEN··············· 'Right whisker contacts
··· GOSUB back_up····················· 'Back up and turn left
··· GOSUB turn_left
··· HIGH 1
· ELSE································ 'Both whiskers 1, no contacts
··· LOW 10
··· LOW 1
··· GOSUB forward_pulse··············· 'Apply a forward pulse
· ENDIF······························· 'and check again
LOOP
forward_pulse:························ 'Send a single pulse forward.
·· PULSOUT 13, 850
·· PULSOUT 12, 680
·· PAUSE 20
· RETURN
turn_left:···························· 'Left turn, about 90-degrees
· FOR pulsecount = 0 TO 20
··· PULSOUT 13, 650
··· PULSOUT 12, 650
··· PAUSE 20
· NEXT
· RETURN
turn_right:··························· 'Right turn, about 90-degrees
· FOR pulsecount = 0 TO 20
··· PULSOUT 13, 850
··· PULSOUT 12, 850
··· PAUSE 20
· NEXT
· RETURN
back_up:······························ 'Back up
· FOR pulsecount = 0 TO 40
··· PULSOUT 13, 650
··· PULSOUT 12, 820
··· PAUSE 20
· NEXT
· RETURN