BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – POLLWAIT
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 337
In this example, the POLLIN command sets I/O pin 0 to be a polled-input
pin looking for a low (0) state. The Main routine immediately runs a
POLLWAIT command and specifies a Duration of 2 (which results in a
low-power state of 72 ms). This means that every 72 ms, the BASIC Stamp
wakes-up and checks I/O pin 0 for a low. If I/O pin 0 is high, it goes back
to sleep for another 72 ms. If I/O pin 0 is low, it runs the next line of code,
which toggles the state of I/O pin 1. Then the loop starts all over again.
Note: Due to the nature of low-power mode, I/O pin 1 may toggle
between high and low (at 72 ms intervals in this case) even if I/O pin 0
stays high. This is an artifact of the "reset" condition in the interpreter chip
that occurs when the chip wakes up from a low-power state. Upon this
"reset" condition, all the I/O pins are switched to inputs for approximately
18 ms. It is the switching to inputs that will cause I/O pin 1 to appear to
toggle. See the NAP or SLEEP commands for more information.
If low-power mode is not required, change the POLLWAIT command in
the example above to "POLLWAIT 8" instead. This will have the effect of
keeping the BASIC Stamp in normal running mode (i.e.: no low-power
glitches) and will also cause the TOGGLE command to execute in a much
shorter amount of time after a polled-input event occurs.
Demo Program (POLLWAIT.bsp)
' POLLWAIT.bsp
' This program demonstrates the POLLWAIT command. I/O pin 0 is set to
' watch for a low signal. Once the Main routine starts running, the
' POLLWAIT command causes the program to halt until the polled event
' happens (I/O pin is low) then it prints a message on the PC screen.
' It will do nothing until I/O pin is low.
' {$STAMP BS2p}
' {$PBASIC 2.5}
Setup:
POLLIN 0, 0 ' polled-input, look for 0
POLLMODE 2 ' enable polling
Main:
POLLWAIT 8 ' Wait for polled event
DEBUG "I/O pin 0 is LOW!", CR ' Print message
GOTO Main
END
NOTE: This example program can be
used with the BS2p, BS2pe, and BS2px
by changing the $STAMP directive
accordingly.