BASIC stamp manual v2.2
BUTTON – BASIC Stamp Command Reference
Page 138 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
ensure that the contact remains in a specified state for a minimum
duration, spurious multiple inputs caused by contact noise can be
eliminated. The BUTTON instruction helps prevent this noise from being
interpreted as more than one switch action; this is the function of the Delay
parameter. For a demonstration of switch bounce, see the demo program
for the COUNT instruction. Delay, combined with the Rate argument,
allows the programmer to control the rate at which multiple inputs are
accepted by the BASIC Stamp.
BUTTON also lets PBASIC react to a button press the way your computer
keyboard does to a key press. When you press a key, a character
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 for use inside a program loop. Each time through
the loop, BUTTON checks the state of the specified pin. When it first
matches DownState, BUTTON begins the Delay countdown for auto-repeat.
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. The Workspace variable is used by BUTTON to keep
track of how many cycles have occurred since the Pin switched to
TargetState or since the last auto-repeat.
BUTTON does not stop program execution. In order for its delay and
auto-repeat functions to work properly, BUTTON must be executed from
within a program loop.