Chapter 6: Light Sensitive Navigation with Photoresistors
· Page 233
"FlashlightControlledBoeBot.bs2" and "RoamingTowardTheLight.bs2". A
sample solution is shown below.
' -----[ Title ]-------------------------------------------------------
' Robotics with the Boe-Bot - AvoidBlackSpots.bs2
' Boe-Bot avoids black pieces of paper.
' {$STAMP BS2} ' Stamp directive
' {$PBASIC 2.5} ' PBASIC directive.
' -----[ Constants ]---------------------------------------------------
LeftWhite CON 16
RightWhite CON 33
LeftBlack CON 26
RightBlack CON 45
LeftAvg CON Lef LeftBlack / 2
RightAvg CON Righ RightBlack / 2
' -----[ Variables ]---------------------------------------------------
timeLeft VAR Word ' Left photoresistor
reading
timeRight VAR Word ' Right photoresistor
reading
' -----[ Initialization ]----------------------------------------------
FREQOUT 4, 2000, 3000
' -----[ Main Routine ]------------------------------------------------
DO
GOSUB Test_Photoresistors
GOSUB Navigate
LOOP
' -----[ Subroutines --------------------------------------------------
Test_Photoresistors:
HIGH 6 ' Left RC time
Measurement.
PAUSE 3
RCTIME 6,1,timeLeft
HIGH 3 ' Right RC time
measurement.
PAUSE 3
RCTIME 3,1,timeRight
RETURN
Navigate: