Datasheet
Page 172· Applied Robotics with the SumoBot
that state while pbSense = 1, and the other that transitions to LED off when
pbSesnse = 0.
State diagrams can be visual aids for describing the different states in certain programs
along with the conditions the programs use to transition from one state to the next. For
example, PushbuttonLed.bs2 can be thought of as the instructions to make the SumoBot a
state machine implementation of Figure 4-9.
Example Program: PushbuttonLed.bs2
√ Enter, save, and run PushbuttonLed.bs2
√ Monitor the LED and Debug Terminal as you press and hold and then release the
pushbutton on the SumoBot's breadboard. Do you agree that this program really
does implement the state machine diagram in Figure 4-9? Is it the only way the
figure can be implemented?
' Applied Robotics with the SumoBot - PushbuttonLed.bs2
' Simple finite state machine example.
' {$STAMP BS2}
' {$PBASIC 2.5}
pbSense PIN 6
LedSpeaker PIN 5
LOW LedSpeaker
DO
IF pbSense = 1 THEN
DEBUG HOME, "State = Blink LED"
TOGGLE LedSpeaker
ELSE
DEBUG HOME, "State = Led off", CLREOL
LOW LedSpeaker
ENDIF
PAUSE 100
LOOP