BASIC stamp manual v2.2
COMPARE – BASIC Stamp Command Reference
Page 142 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
input voltage on P1 was greater than that of P2. Result and the output pin
P0 will be 1 if the input voltage on P1 was less than that of P2.
Note that the comparator hardware operates independently of the
execution speed of the BS2px and will continue to run and update P0 if
Mode = 1, even during sleep mode (execution of END, NAP, POLLWAIT 8,
or SLEEP commands). To avoid spurious current draw during sleep
mode, disable the comparator first.
Demo Program (COMPARE.bpx)
' COMPARE.bpx
' This example demonstrates the use of the COMPARE command.
' Connect two variable voltage sources (0 to 5 volts) on I/O pins
' P1 and P2 (or a button on each pin connected to ground). Run the program
' and watch the Debug Terminal display as you adjust the variable voltage
' or press the buttons.
' {$STAMP BS2px}
' {$PBASIC 2.5}
Result VAR Bit
#IF $STAMP <> BS2PX #THEN
#ERROR "This program requires a BS2px."
#ENDIF
Setup:
CONFIGPIN DIRECTION, %0000000000000001 'P0 = output, all others = input
CONFIGPIN PULLUP, %0000000000000110 'Enable pull-ups on P1 and P2
DEBUG "BS2px COMPARATOR DEMONSTRATION", CR,
"==============================", CR,
"Input Voltage: P1 > P2", CR,
"Output State: P0 = 0"
Main:
DO 'Display P1/P2 comparison
COMPARE 1, Result
IF Result = 0 THEN
DEBUG CRSRXY,18,2,">"
ELSE
DEBUG CRSRXY,18,2,"<"
ENDIF
DEBUG CRSRXY,20,3,BIN1 Result
LOOP
NOTE: This example program can be
used only with the BS2px.