Page 216 ·
Robotics with the Boe-Bot
FREQOUT 4, 2000, 3000
' -----[ Main Routine ]-------------------------------------------------------
DO
GOSUB Test_Photoresistors
GOSUB Navigate
LOOP
' -----[ Subroutine - Test_Photoresistors ]-----------------------------------
Test_Photoresistors:
HIGH 6 ' Left RC time measurement.
PAUSE 3
RCTIME 6,1,timeLeft
HIGH 3 ' Right RC time measurement.
PAUSE 3
RCTIME 3,1,timeRight
RETURN
' -----[ Subroutine - Navigate ]----------------------------------------------
Navigate:
IF (timeLeft < LeftThreshold) AND (timeRight < RightThreshold) THEN
PULSOUT 13, 850 ' Both detect flashlight beam,
PULSOUT 12, 650 ' full speed forward.
ELSEIF (timeLeft < LeftThreshold) THEN ' Left detects flashlight beam,
PULSOUT 13, 700 ' pivot left.
PULSOUT 12, 700
ELSEIF (timeRight < RightThreshold) THEN ' Right detects flashlight beam,
PULSOUT 13, 800 ' pivot right.
PULSOUT 12, 800
ELSE
PULSOUT 13, 750 ' No flashlight beam, sit still.
PULSOUT 12, 750
ENDIF
PAUSE 20 ' Pause between pulses.
RETURN