Datasheet

Chapter 2: EEPROM Tricks and Program Tips · Page 69
NEXT
PAUSE 1000 ' 1 second between beeps
IF pbSense = 0 THEN ' Button released?
WRITE ModeSelect, temp ' Record mode to EEPROM
EXIT ' Exit FOR...NEXT loop
ENDIF
NEXT
RETURN
Your Turn
Try modifying PushbuttonMode.bs2 so that you can choose different forward
distances to make the SumoBot travel in case you have to repeat plow
adjustments or other tests.
ACTIVITY #6: INTEGRATING PROGRAMS
PBASIC application programs typically contain the following sections:
Title or heading information
Compiler definitions
I/O Definitions
Constant declarations
Variable declarations
EEPROM Data
Initialization
Main Routine
Subroutines
There are several reasons for all these sections. First, it helps prevent larger programs
from getting out of hand by keeping them well organized. Second, it makes the program
more readable. Third, it helps keep the elements in each program modular.
Modular program components are really important. Why? Because it makes it possible
to re-use components from a previous project in new projects. For example, let's say you
move on from SumoBots to a complex maze solving contest. If you developed lots of
valuable techniques with your SumoBot, you may want to copy selected subroutines into
the maze solving robot's program. If your code follows conventions to keep it modular,
you'll be able to do this with minimal hassle.