BASIC stamp manual v2.2

5: BASIC Stamp Command Reference – POLLOUT
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 329
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 within the circuitry connected to I/O pin 0, so it is
vital that a large enough series resistor (perhaps 100 ohms or greater) be
inserted on that pin to protect the external device and the BASIC Stamp.
Demo Program (POLL.bsp)
' POLL.bsp
' This program demonstrates POLLIN, POLLOUT, and the use of the POLLMODE
' instruction. Connect active-low inputs to pins 0, 1, 2, and 3. Then
' connect an LED to pin 7. The program will print "." to the Debug
' window until one of the alarm buttons are pressed. This will cause
' the termination of the main loop. At this point the program will
' save the latched bits, clear them (and the polling process), then
' report the input(s) that triggered the alarm.
' {$STAMP BS2p}
' {$PBASIC 2.5}
FDoor PIN 0
BDoor PIN 1
Patio PIN 2
Rst PIN 3
AlarmLed PIN 7
alarms VAR Byte ' alarm bits
idx VAR Nib ' loop control
Setup:
POLLIN FDoor, 0 ' define alarm inputs
POLLIN BDoor, 0
POLLIN Patio, 0
POLLOUT AlarmLed, 1 ' alarm indicator
POLLMODE 10 ' activate latched polling
DEBUG CLS,
"Alarms Activated", CR
Main:
DO
DEBUG "." ' foreground activity
PAUSE 50
LOOP UNTIL (AlarmLed = 1) ' loop until LED is on
GET 128, alarms ' get alarm bits
POLLMODE 0 ' deactivate polling
Report:
DEBUG CLS, ' alarms report
NOTE: This example program can be
used with the BS2p, BS2pe, and BS2px
by changing the $STAMP directive
accordingly.