Chapter 7: Navigating with Infrared Headlights · Page 259
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
DO ' Main Routine.
FREQOUT 8, 1, 38500 ' Check IR detectors.
irDetectLeft = IN9
FREQOUT 2, 1, 38500
irDetectRight = IN0
' Decide navigation.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseCount = 1 ' Both detected,
pulseLeft = 850 ' one pulse forward.
pulseRight = 650
ELSEIF (irDetectRight = 1) THEN ' Right not detected,
pulseCount = 10 ' 10 pulses left.
pulseLeft = 650
pulseRight = 650
ELSEIF (irDetectLeft = 1) THEN ' Left not detected,
pulseCount = 10 ' 10 pulses right.
pulseLeft = 850
pulseRight = 850
ELSE ' Neither detected,
pulseCount = 15 ' back up and try again.
pulseLeft = 650
pulseRight = 850
ENDIF
FOR loopCount = 1 TO pulseCount ' Send pulseCount pulses
PULSOUT 13,pulseLeft
PULSOUT 12,pulseRight
PAUSE 20
NEXT
LOOP
How AvoidTableEdge.bs2 Works
Since this program is a modified version of FastIrRoaming.bs2, only changes to the program
are discussed here.
A FOR…NEXT loop is added to the program to control how many pulses are delivered each
time through the main (
DO…LOOP) routine. Two variables are added, loopCount
functions as an index for a
FOR…NEXT loop and pulseCount is used as the EndValue
argument.
loopCount VAR Byte