Datasheet

Page 252 ยท Robotics with the Boe-Bot
DO
PULSOUT 13, 790 ' Rotate slowly
PULSOUT 12, 790
PAUSE 15 ' 5 ms for detectors
GOSUB Check_IRs ' While looking for object
LOOP UNTIL (irDetectLeft = 0) OR (irDetectRight = 0)
' Now figure out exactly where the object is and go toward it
DO
' Object in both detectors -- go forward
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
pulseLeft = 850 ' Forward
pulseRight = 650
' Object on left - go left
ELSEIF (irDetectLeft = 0) THEN
pulseLeft = 650 ' Left toward object
pulseRight = 650
' Object on right - go right
ELSEIF (irDetectRight = 0) THEN
pulseLeft = 850 ' Right toward object
pulseRight = 850
' No object -- go forward anyway, because the detectors will
ELSE ' momentarily show
pulseLeft = 850 ' "no object" as the
pulseRight = 650 ' Boe-Bot is adjusting
ENDIF ' its position.
PULSOUT 13,pulseLeft ' Apply the pulse.
PULSOUT 12,pulseRight
PAUSE 15 ' 5 ms for detectors
' Check IRs again in case object is moving
GOSUB Check_IRs
LOOP
' -----[ Subroutines ] ------------------------------------------------
Check_IRs:
FREQOUT 8, 1, 38500 ' Check IR Detectors
irDetectLeft = IN9
FREQOUT 2, 1, 38500
IrDetectRight = IN0
RETURN
P3. The key to solving this problem is to combine "FastIrRoaming.bs2" and
"IrInterferenceSniffer.bs2" in a single program.
' -----[ Title ]-------------------------------------------------------
' Robotics with the Boe-Bot - RoamAndSniffBoeBot.bs2
' Boe-Bot roams around and sounds alarm when IR detected.