EasyManua.ls Logo

Parallax Boe-Bot - Page 265

Parallax Boe-Bot
360 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 7: Navigating with Infrared Headlights · Page 251
FREQOUT 4, 2000, 3000 ' Signal program start/reset.
' -----[ Main Routine ]-------------------------------------------------------
DO
FREQOUT 8, 1, 38500 ' Store IR detection values in
irDetectLeft = IN9 ' bit variables.
FREQOUT 2, 1, 38500
irDetectRight = IN0
IF (irDetectLeft = 0) AND (irDetectRight = 0) THEN
GOSUB Back_Up ' Both IR pairs detect obstacle
GOSUB Turn_Left ' Back up & U-turn (left twice)
GOSUB Turn_Left
ELSEIF (irDetectLeft = 0) THEN ' Left IR pair detects
GOSUB Back_Up ' Back up & turn right
GOSUB Turn_Right
ELSEIF (irDetectRight = 0) THEN ' Right IR pair detects
GOSUB Back_Up ' Back up & turn left
GOSUB Turn_Left
ELSE ' Both IR pairs 1, no detects
GOSUB Forward_Pulse ' Apply a forward pulse
ENDIF ' and check again
LOOP
' -----[ Subroutines ]--------------------------------------------------------
Forward_Pulse: ' Send a single forward pulse.
PULSOUT 13,850
PULSOUT 12,650
PAUSE 20
RETURN
Turn_Left: ' Left turn, about 90-degrees.
FOR pulseCount = 0 TO 20
PULSOUT 13, 650
PULSOUT 12, 650
PAUSE 20
NEXT
RETURN
Turn_Right:
FOR pulseCount = 0 TO 20 ' Right turn, about 90-degrees.
PULSOUT 13, 850
PULSOUT 12, 850
PAUSE 20
NEXT
RETURN

Table of Contents

Other manuals for Parallax Boe-Bot