Datasheet
Page 12ยท Applied Robotics with the SumoBot
DEBUG "Main program running...", CR ' Display program status
' -----[ Main Routine ]-------------------------------------------------------
FOR counter = 1 TO 100 ' Deliver 100 forward pulses
PULSOUT ServoLeft, 850
PULSOUT ServoRight, 650
PAUSE 20
NEXT
DEBUG "Done!", CR, ' User instructions
"Press/release reset", CR,
"twice to restart...", CR
END
Understanding Forward100Pulses.bs2
When you click the BASIC Stamp Editor's Run button, the program downloads to the
SumoBot's BASIC Stamp. The
Reset_Button routine in the Initialization displays the
message "Press/release Reset...", then it ends the program. When you press and release
the Reset button on the SumoBot board, the same
Reset_Button routine displays the
message "Main program running..." and moves on to the Main Routine and the servos
start turning. If you leave the SumoBot connected to its serial cable and press/release the
Reset button a third time, you will again see the "Press/release Reset button" prompt.
Repeat a fourth time, and the servos will run for a couple seconds.
The reason the
Reset_Button routine is able to perform this function is because it
manipulates values stored in the SumoBot's EEPROM program memory. The portion of
this memory that is not used to store the program can be used to store values. While the
BASIC Stamp's RAM memory is erased whenever the power is turned off or the Reset
button is pressed and released, the EEPROM memory retains the values stored in it.
That's why the same program runs after your turn the SumoBot's power off, then back on.
The ability to retrieve values stored in EEPROM, change them, and store them back into
EEPROM is what allows the
Reset_Button routine to track whether you've pressed and
released the Reset button an odd or even number of times. The mechanics of exactly how
the
Reset_Button routine does this is covered in more detail in Chapter 2, Activity #2.
For now, just keep in mind that the
Reset_Button routine allows the program to
continue to the Main Routine when you have pressed and released the SumoBot's Reset
button an odd number of times. That means, the first, third, fifth,... time you press and
release the Reset button, the program will continue to the Main Routine, and the servos
will turn for about 2 1/2 seconds. Whenever you have pressed/released the Reset button