Datasheet
Page 70· Applied Robotics with the SumoBot
One of the most important ingredients of modular programs is keeping the same naming
conventions for variables. For example, in this book,
temp is a temporary variable that is
used to receive and manipulate stored information and sensor measurements. After
decisions are made based on
temp in one subroutine, temp is always free to be used in the
next subroutine. The same applies to the
counter variable. When it's done counting in a
loop in one subroutine, it is free to count in a different loop in the next subroutine.
In this activity, you will combine two programs that were developed in this chapter:
TestResetButton.bs2 from Activity #3, and PushbuttonMode.bs2 from Activity #5.
Because both programs follow the same rules for sectioning and temporary variable use,
they will be really easy to combine. Both of these programs have clearly defined
sections (I/O Definitions, Variables, EEPROM Data, Subroutines and so on). Both
programs also follow the same naming conventions for reusable variables like
temp and
counter. As you will see, these are two key ingredients for making all of your test and
application programs building blocks for future programs.
Combining the Reset and Pushbutton Mode Programs
The first step to combining TestResetButton.bs2 and PushbuttonMode.bs2 is to save a
copy of one of the programs. We'll start by saving TestResetButton.bs2 as
ResetAndStartMode.bs2. Then, we'll copy the elements from PushbuttonMode.bs2 that
were not already in TestResetButton.bs2. For example, TestResetButton.bs2 already had
the
LedSpeaker PIN directive, but not the pbSense PIN directive. So, the pbSense
PIN
directive will be copied from PushbuttonMode.bs2 to the new
ResetAndStartMode.bs2. After repeating this process for each section (Variables,
EEPROM Data, Initialization, etc), we'll have a complete program that performs both the
reset-start function and the mode-select function.
√ Open TestResetButton.bs2 and save it as ResetStartAndMode.bs2
√ Open PushbuttonMode.bs2.
√ Copy the
pbSense PIN directive from the I/O definitions section in
PushbuttonMode.bs2, and paste it into the I/O definitions section in
ResetAndStartMode.bs2.
√ Copy the
ModeSelect DATA directive from the EEPROM Data section in
PushbuttonMode.bs2, and paste it to the EEPROM Data section in
ResetAndStartMode.bs2.