Datasheet

Page 64· Applied Robotics with the SumoBot
pbSense PIN 6 ' Pushbutton connected to P6
' -----[ Initialization ]-----------------------------------------------------
DEBUG CLS, "Press/hold/release" , CR, ' PROMPT press/release pushbutton
"pushbutton on", CR,
"breadboard...", CR
' -----[ Main Routine ]-------------------------------------------------------
DO ' DO...LOOP repeats indefinitely
DEBUG BIN1 pbSense ' Display state of pbSense (IN6)
PAUSE 100 ' Delay for slower PCs
LOOP
Your Turn - Controlling the LED with the Pushbutton
After adding the LedSpeaker PIN directive to this program, you can make the LED
flash on/off while you hold down the pushbutton. All it takes in an
IF...THEN added to
the
DO...LOOP in the main routine.
Save a copy of the program as TestPushButtonYourTurn.bs2.
Add the
PIN directive LedSpeaker PIN 5.
Replace the
DO...LOOP in the Main Routine with this one:
DO ' DO...LOOP repeats indefinitely
DEBUG BIN1 pbSense ' Display state of pbSense (IN6)
IF pbSense = 1 THEN ' Flash LED if pbSense = 1
TOGGLE LedSpeaker
ELSE
LOW LedSpeaker ' Otherwise, keep pin low
ENDIF
PAUSE 100 ' Delay for slower PCs
LOOP
Run the program and verify that you now have pushbutton control of the LED.
Save the modified program.
For fun, try modifying the program so that it plays a list of notes when you
press/release the button.