Page 84 ·
Robotics with the Boe-Bot
Example Program: BothServosThreeSeconds.bs2
Here’s an example of making the servos turn in one direction for three seconds, then
reversing their direction.
√
Enter, save, and run BothServosThreeSeconds.bs2.
' Robotics with the Boe-Bot - BothServosThreeSeconds.bs2
' Run both servos in opposite directions for three seconds, then reverse
' the direction of both servos and run another three seconds.
' {$STAMP BS2}
' {$PBASIC 2.5}
DEBUG "Program Running!"
counter VAR Byte
FOR counter = 1 TO 122
PULSOUT 13, 850
PULSOUT 12, 650
PAUSE 20
NEXT
FOR counter = 1 TO 122
PULSOUT 13, 650
PULSOUT 12, 850
PAUSE 20
NEXT
END
Verify that each servo turned one direction for three seconds, and then reversed direction
and turned for three more seconds. Did you notice that while the servos reversed at the
same moment, they were always turning in opposite directions? Why would this be
useful?
Your Turn – Predict Servo Run Time
√
Pick a time (six seconds or less), that you want your servos to turn.
√
Divide the number of seconds by 0.024.
√
Your answer is the number of loops you will need.
√
Modify BothServosThreeSeconds.bs2 so that it makes both servos run for the
amount of time you selected.
√
Compare your predicted run time to the actual run time.