POLLOUT - BASIC Stamp Command Reference
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-output to be the same
as the polled-input.
respond in some way if a polled-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:
POLLOUT 0, 1
POLLIN 0, 1
POLLMODE 10
Idx VAR
BYTE
Work:
FOR Idx = 1 TO 20
DEBUG "Working...", CR
NEXT
IF OUT0 = 0 THEN Work
Respond:
DEBUG CR, "Hey! You set my pin high!", CR
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.
Since the POLLIN command occurred after the POLLOUT, I/O pin 0 will
be an input, but the polling feature will still affect the OUT0 bit (output
latch for I/O pin 0). Then, the program performs some work, and once in
a while, checks the state of OUT0. If OUT0 is 0, I/O pin 0 was never seen
to go high. If, however, OUT0 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 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.
It is important to note that during the time between the POLLOUT and
POLLIN commands, I/O pin 0 will be set to an output direction. This can
cause a temporary short with the circuitry connected to I/O pin 0, so it is
Page 228 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com
For example, suppose an application needed to
'Set I/O 0 to polled-output, high
'Set I/O 0 back to polled-input, high
'Set mode to latch the polled-output
'Do nonsense work, but check once in a
'while to see if the polled event ever occured
'Send a different message if it did occur
'Reset polled-output's latch function
A
POLLOUT
CLEVER TRICK WITH
"L
"
AND THE
ATCHED
FEATURE
.
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?