Chapter 6: Light Sensitive Navigation with Photoresistors
· Page 201
Casting shadows over both photoresistors at the same time can be difficult
. When the
Boe-Bot is going forward, it is checking the photoresistors around 40 times/second. You will
have to move quickly to cast a shadow over both photoresistors between pulses. It helps to
move your hand rapidly from no shade to full shade to trigger both photoresistors at once.
Alternately, just leave your hand casting shade over both photoresistors while it executes a
maneuver. When it returns from the maneuver and checks the photoresistors again, it
should recognize that both photoresistors are in shade.
√
Verify that the Boe-Bot avoids shadows by using your hand to cast a shadow
over the photoresistors. Try no shadow, a shadow over the right photoresistor
divider (circuit connected to P3), a shadow over the left photoresistor divider
(circuit connected to P7), and a shadow over both photoresistor dividers.
√
Update the comments such as the title and descriptions of reactions to whisker
presses to reflect the photoresistor circuit behavior. It should resemble the
program below when you are done.
' -----[ Title ]--------------------------------------------------------------
' Robotics with the Boe-Bot - RoamingWithPhotoresistorDividers.bs2
' Boe-Bot detects shadows photoresistors voltage divider circuit and turns
' away from them.
' {$STAMP BS2} ' Stamp directive.
' {$PBASIC 2.5} ' PBASIC directive.
DEBUG "Program Running!"
' -----[ Variables ]----------------------------------------------------------
pulseCount VAR Byte ' FOR...NEXT loop counter.
' -----[ Initialization ]-----------------------------------------------------
FREQOUT 4, 2000, 3000 ' Start/restart signal.
' -----[ Main Routine ]-------------------------------------------------------
DO
IF (IN6 = 0) AND (IN3 = 0) THEN ' Both photoresistors detects
GOSUB Back_Up ' shadow, back up & U-turn
GOSUB Turn_Left ' (left twice).
GOSUB Turn_Left
ELSEIF (IN6 = 0) THEN ' Left photoresistor detects
GOSUB Back_Up ' shadow, back up & turn right.
GOSUB Turn_Right
ELSEIF (IN3 = 0) THEN ' Right photoresistor detects
GOSUB Back_Up ' shadow, back up & turn left.
GOSUB Turn_Left