BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – POLLIN
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 315
pin 0 is set low, the BASIC Stamp will set I/O pin 1 high. It will continue
to perform this operation, in-between each command in the loop,
endlessly.
It's important to note that, in this example, only the DEBUG and GOTO
commands are being executed over and over again. The first three lines of
code are only run once, yet their effects are "remembered" by the BASIC
Stamp throughout the rest of the program.
If the polling commands were not used, the program would have to look
like the one below in order to achieve the same effect.
INPUT 0
OUTPUT 1
Main:
OUT1 = ~IN0
DEBUG "Looping...", CR
OUT1 = ~IN0
GOTO Main
In this example, we create the inverse relationship of input pin 0 and
output pin 1 manually, in-between the DEBUG and GOTO lines. Though
the effects are the same as when using the polling commands, this
program actually takes a little longer to run and consumes 7 additional
bytes of program (EEPROM) space. Clearly, using the polling commands
is more efficient.
You can have as many polled-input and polled-output pins as you have
available. If multiple polled-input pins are defined, any one of them can
trigger changes on the polled-output pins that are also defined. For
example:
POLLIN 0, 0
POLLIN 1, 0
POLLOUT 2, 1
POLLOUT 3, 1
POLLMODE 2
Main:
DEBUG "Looping...", CR
GOTO Main
This code sets I/O pins 0 and 1 to polled-input pins (looking for a low (0)
state) and sets I/O pins 2 and 3 to polled-output pins (with a high-active
FOR COMPARISON: ACHIEVING THE SAME
EFFECTS WITHOUT THE POLLING
COMMANDS
.
U
SING MULTIPLE POLLED-INPUT AND
POLLED
-OUTPUT PINS.
T
HE BASIC STAMP "REMEMBERS" THE
POLLING CONFIGURATION FOR THE
DURATION OF THE
PBASIC PROGRAM.