Datasheet
Page 48· Applied Robotics with the SumoBot
READ EepromCounter, temp
To make the program count the number of consecutive resets, simply add 1 to the value
of
temp and write it back to the EEPROM byte at the EepromCounter address. Next
time the program starts, the value the
READ command fetches will be higher by 1.
temp = temp + 1
WRITE EepromCounter, temp
The program can then make decisions based on the value of the temp variable. To
simplify things, the next example program subtracts 1 from
temp before analyzing it with
the
IF...THEN statement. Subtracting 1 from temp is not necessary, it just makes the
Your Turn section a little easier to follow.
temp = temp - 1
IF temp = 0 THEN
DEBUG "Since download, you have", CR,
"pressed Reset ", DEC temp,
" times.", CR
ELSE
DEBUG CRSRX, 11, "...", DEC temp,
" times.", CR
ENDIF
Example Program: ResetButtonCounter.bs2
This program displays the number of times you have pressed and released the SumoBot's
Reset button after the program was downloaded.
√ Enter, save, and run ResetButtonCounter.bs2.
√ Watch the Debug Terminal as you repeatedly press/release the SumoBot's Reset
button.
' Applied Robotics with the SumoBot - ResetButtonCounter.bs2
' {$STAMP BS2}
' {$PBASIC 2.5}
EepromCounter DATA 0
temp VAR Byte
READ EepromCounter, temp