BASIC stamp manual v2.2
POLLOUT – BASIC Stamp Command Reference
Page 328 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
however, where the polled-output pins will latch the active state; they will
change only once (when the poll state is reached) and stay in the new state
until the PBASIC program tells it to change again. See the POLLMODE
description for more information.
A clever use of the "latched" feature is to set a polled input on the same pin
as a polled output. This leaves the pin in an input state, and the “latched”
state of that input pin will be saved in the pin’s output latch bit (which is
otherwise not used because the pin was last set to input mode). This gives
us the advantage of having a run-time readable bit that indicates whether
the input pin changed state while we were busy. For example, suppose an
application needed to respond in some way if an input pin goes high, but
it doesn't need to respond immediately, and the other tasks should not be
interrupted. In essence, we need a way to know if the pin has gone high
since the last time we checked it. Look at this example:
alarm VAR OUT0
idx VAR Byte
Setup:
POLLOUT 0, 1
POLLIN 0, 0
POLLMODE 10
Work:
FOR idx = 1 TO 25
DEBUG "Working...", CR
NEXT
IF (Alarm = 0) THEN Work
Respond:
DEBUG CR, "Hey, the Alarm was tripped!", CR
PAUSE 1000
POLLMODE 10
GOTO Work
Here, we set I/O pin 0 to a polled-output, then immediately set it to a
polled-input. Then we set the polled-mode to latch the polled-outputs.
Afterwards, the program performs some work, and once in a while, checks
the state of OUT0 (named Alarm in the program). If Alarm is 0, I/O pin 0
was never seen to go high. If, however, Alarm is 1, I/O pin 0 must have
gone high while the program was doing other work, and now it can
respond in the proper manner. This even works if the input pin had gone
high and then low again before we check it (as long as it was high at some
point in between the instructions in our Work routine).
A CLEVER TRICK WITH POLLOUT AND
THE
"LATCHED" FEATURE.