Page 218 ·
Robotics with the Boe-Bot
This is the subroutine that performs the
RCTIME
measurements on both photoresistor RC
circuits. The measurement for the left circuit is stored in the
timeLeft
variable, and the
measurement for the right circuit is stored in the
timeRight
variable.
Test_Photoresistors:
HIGH 6
PAUSE 3
RCTIME 6,1,timeLeft
HIGH 3
PAUSE 3
RCTIME 3,1,timeRight
RETURN
The Navigate subroutine uses an
IF…THEN
statement to compare the
timeLeft
variable
against the
LeftThreshold
constant and the
timeRight
variable against the
RightThreshold
constant. Remember, when the
RCTIME
measurement is small, it
means bright light is detected, and when it’s large, it means the light is not as bright. So,
when one of the variables that stores an
RCTIME
measurement is smaller than the
threshold constant, it means the flashlight beam has been detected; otherwise, the
flashlight beam has not been detected. Depending on which condition this subroutine
detects (both, left, right or neither), the correct navigation pulses is applied, followed by a
PAUSE
before the
RETURN
command exits the subroutine.
Navigate:
IF(timeLeft<LeftThreshold)AND(timeRight<RightThreshold) THEN
PULSOUT 13, 850
PULSOUT 12, 650
ELSEIF (timeLeft < LeftThreshold) THEN
PULSOUT 13, 700
PULSOUT 12, 700
ELSEIF (timeRight < RightThreshold) THEN
PULSOUT 13, 800
PULSOUT 12, 800
ELSE
PULSOUT 13, 750
PULSOUT 12, 750
ENDIF