Datasheet
Chapter 2: EEPROM Tricks and Program Tips · Page 71
While all the steps up to this point were purely mechanical, the Initialization section will
take some thought. There are several options. You can put the
IF...THEN statement
from PushbuttonMode.bs2's initialization as the first, second or third step. To make the
decision, think about how the program would work if the
IF...THEN is the first step.
Then, consider how it would work differently if it was the second step, and so on. An
advantage to having it as the first step is that you can set the mode regardless of whether
the main program is going to run or not, so we'll try that.
Example Program: ResetAndStartMode.bs2
√ Copy the IF pbSense = 1 THEN GOSUB Mode_Select from the Initialization
section in PushbuttonMode.bs2, and paste it to the Initialization section in
ResetAndStartMode.bs2.
√ Copy the
ModeTest routine from the main routine in PushbuttonMode.bs2, and
paste it to the beginning of the Main Routine in ResetAndStartMode.bs2. The
ModeTest routine should come before the ResetTest routine.
Be careful with END commands in the main routine. Both the ModeTest and ResetTest
routines contain END statements. If you forget to delete the END command at the end of
the ModeTest routine, you'll never get through the ResetTest routine..
√ If you have not already done so, delete the
END that comes before the
ResetTest routine.
√ Copy the
Mode_Select subroutine from the Subroutines section in
PushbuttonMode.bs2, and paste it to the Subroutines section in
ResetAndStartMode.bs2. Pasting it as the last subroutine in
ResetAndStartMode.bs2 is fine.
√ Update the Title section so that it has the current program name and a correct
program description.
√ Compare your program to ResetAndStartMode.bs2 shown below.
' -----[ Title ]--------------------------------------------------------------
' ---> Updated <---
' Applied Robotics with the SumoBot - ResetAndStartMode.bs2
' Program constructed by copying and pasting code from
' PushbuttonMode.bs2 into TestResetButton.bs2.
' {$STAMP BS2} ' Target = BASIC Stamp 2
' {$PBASIC 2.5} ' Language = PBASIC 2.5