Specifications
BASIC Stamp II
Page 250 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
immediately appears on the screen. If you hold the key down, there’s a
delay, then a rapid-fire stream of characters appears on the screen.
Button’s auto-repeat function can be set up to work much the same way.
Button is designed to be used inside a program loop. Each time through
the loop, Button checks the state of the specified pin. When it first
matches downstate, Button debounces the switch. Then, in accordance
with targetstate, it either branches to address (targetstate = 1) or doesn’t
(targetstate = 0).
If the switch stays in downstate, Button counts the number of program
loops that execute. When this count equals delay, Button once again
triggers the action specified by targetstate and address. Hereafter, if the
switch remains in downstate, Button waits rate number of cycles between
actions.
Button does not stop program execution. In order for its delay and
autorepeat functions to work properly, Button must be executed from
within a program loop.
Demo Program
Connect the active-low circuit shown in figure I-1 to pin P7 of the BS2.
When you press the button, the Debug screen will display an asterisk
(*). Feel free to modify the program to see the effects of your changes on
the way Button responds.
btnWk var byte ' Workspace for BUTTON instruction.
btnWk = 0 ' Clear the workspace variable.
' Try changing the Delay value (255) in BUTTON to see the effect of
' its modes: 0=no debounce; 1-254=varying delays before autorepeat;
' 255=no autorepeat (one action per button press).
Loop:
BUTTON 7,0,255,250,btnWk,0,noPress ' Go to noPress UNLESS..
debug "* " ' ..P7 is 0.
noPress: goto loop ' Repeat endlessly.
+5V
10k
to I/O pin
active-high
(downstate = 1)
+5V
10k
to I/O pin
active-low
(downstate = 0)
Figure I-1










