Page 180 ·
Robotics with the Boe-Bot
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
Back_Up: ' Back up.
FOR pulseCount = 0 TO 40
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN
How Roaming with Whiskers Works
The
IF
...
THEN
statements in the Main Routine section first check the whiskers for any
states that require attention. If both whiskers are pressed (
IN5 = 0
and
IN7 = 0
), a U-
turn is executed by calling the
Back_Up
subroutine followed by calling the
Turn_Left
subroutine twice in a row. If just the left whisker is pressed (
IN5 = 0
), then the program
calls the
Back_Up
subroutine followed by the
Turn_Right
subroutine. If the right
whisker is pressed
(IN7 = 0
), the
Back_Up
subroutine is called, followed by the
Turn_Left
subroutine. The only possible combination that has not been covered is if
neither whisker is pressed (
IN5 = 1
and
IN7 = 1
). The
ELSE
command calls the
Forward_Pulse
subroutine in this case.
IF (IN5 = 0) AND (IN7 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
GOSUB Turn_Left
ELSEIF (IN5 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Right
ELSEIF (IN7 = 0) THEN
GOSUB Back_Up
GOSUB Turn_Left
ELSE
GOSUB Forward_Pulse
ENDIF