NOTE: This is written for the BS2p and will also run on the BS2pe and BS2px. Modify the $STAMP directive (as required) before downloading to the BS2pe or BS2px.
' 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 "Front Door : ", CR, "Back Door : ", CR, "Patio : ", CR FOR idx = 0 TO 2 ' scan alarm bits DEBUG CRSRXY, 13, idx ' move cursor IF (alarms.LOWBIT(idx)) THEN ' report each bit status DEBUG "Alarm", CR ELSE DEBUG "-", CR ENDIF NEXT DEBUG CR, "Press RESET to clear..." DO : LOOP UNTIL (Rst = 0) ' wait until Rst pressed GOTO Setup END
BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012