Chapter 6: Light Sensitive Navigation with Photoresistors
· Page 217
How FlashlightControlledBoeBot.bs2 Works
These are the four constant declarations that you used with your own values from Table
6-1.
LeftAmbient CON 108
RightAmbient CON 114
LeftBright CON 20
RightBright CON 22
Now that the four constants have been declared, the next two lines average and scale the
values to come up with threshold values for the program. These threshold values can be
compared with the current
timeLeft
and
timeRight
measurements to determine
whether the photoresistors are sensing ambient light or a focused beam.
' Average Scale
LeftThreshold CON Left LeftAmbient / 2 * 5 / 8
RightThreshold CON Right RightAmbient / 2 * 5 / 8
These variables are used to store the
RCTIME
measurements.
timeLeft VAR Word
timeRight VAR Word
This is the reset indicator that has been used in most of the programs in this text.
FREQOUT 4, 2000, 3000
The Main Routine section contains just two subroutine calls. All the actual work in the
program occurs in the two subroutines.
Test_Photoresistors
takes the
RCTIME
measurements for both RC photoresistor circuits, and the
Navigate
subroutine makes the
decisions and delivers the servo pulses.
DO
GOSUB Test_Photoresistors
GOSUB Navigate
LOOP