Chapter 7: Navigating with Infrared Headlights
· Page 253
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
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 how to navigate.
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 850
ELSEIF (irDetectLeft = 0) THEN
pulseLeft = 850
pulseRight = 850
ELSEIF (irDetectRight = 0) THEN
pulseLeft = 650
pulseRight = 650
ELSE
pulseLeft = 850
pulseRight = 650
ENDIF
PULSOUT 13,pulseLeft ' Apply the pulse.
PULSOUT 12,pulseRight
PAUSE 15
LOOP ' Repeat main routine
How FastIrRoaming.bs2 Works
This program takes a slightly different approach to applying pulses. Aside from the two
bits used to store the IR detector outputs, it uses two word variables to set the pulse
durations delivered by the
PULSOUT
command.
irDetectLeft VAR Bit
irDetectRight VAR Bit
pulseLeft VAR Word
pulseRight VAR Word
Inside the
DO…LOOP
, the
FREQOUT
commands are used to send a 38.5 kHz IR signal to
each IR LED. Immediately after the 1 ms burst of IR is sent, a bit variable stores the
output state of the IR detector. This is necessary, because if you wait any longer than a