# COMPARE Example

Sytnax: COMPARE

    ' 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}

    #IF $STAMP <> BS2PX #THEN
      #ERROR "This program requires a BS2px."
    #ENDIF

    result  VAR Bit

    Setup:
      ' P0 = output, all others = input
      CONFIGPIN DIRECTION, %0000000000000001
      ' Enable pull-ups on P1 and P2
      CONFIGPIN PULLUP, %0000000000000110

      DEBUG CLS,
            "BS2px Comparator Demonstration", CR,
            "==============================", 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, 3, ">"
        ELSE
          DEBUG CRSRXY, 18, 3, "<"
        ENDIF
        DEBUG CRSRXY, 19, 4, BIN1 result
      LOOP

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012