Page 204 · Robotics with the Boe-Bot
Boe-Bot should move forward. If you cast a shadow over one of the photoresistors, the
Boe-Bot should turn in the direction of the photoresistor that senses the shadow.
√
Enter, save, and run ShadowGuidedBoeBot.bs2.
√
Use your hand to cast shadows over the photoresistor dividers.
√
Study this program carefully and make sure you understand how it works. It is
very short, yet very powerful.
' Robotics with the Boe-Bot - ShadowGuidedBoeBot.bs2
' Boe-Bot detects shadows cast by your hand and tries to follow them.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
FREQOUT 4, 2000, 3000
DO
IF (IN6
= 0) AND (IN3 = 0) THEN
PULSOUT 13, 850
PULSOUT 12, 650
ELSEIF (IN6
= 0) THEN
PULSOUT 13, 750
PULSOUT 12, 650
ELSEIF (IN3
= 0) THEN
PULSOUT 13, 850
PULSOUT 12, 750
ELSE
PULSOUT 13, 750
PULSOUT 12, 750
ENDIF
PAUSE 20
LOOP
How ShadowGuidedBoeBot.bs2 Works
The
statement in the
IF...THEN
conditions: both, left, right, neither. Depending on which condition is detected,
commands deliver pulses for one of the following maneuvers: forward, pivot right, pivot
left, or sit still. Regardless of the condition, one of the four sets of pulses will be
delivered each time through the
remember to include the
pulses.
looks for one of the four possible shadow
DO...LOOP
. After the
DO...LOOP
to ensure the low time between each pair of servo
PAUSE 20
' Stamp directive.
' PBASIC directive.
' Start/restart signal.
' Both detect shadows, forward.
' Left detects shadow,
' pivot left.
' Right detects shadow,
' pivot right.
' No shadow, sit still
' Pause between pulses.
statement, it's important to
IF...THEN
PULSOUT
Need help?
Do you have a question about the Boe-Bot and is the answer not in the manual?
Questions and answers