# TOGGLE Examples

Syntax: TOGGLE

Connect four LEDs and four 470 Ω resistors as show below for the demo program.

    ' TOGGLE.BS1
    ' Connect LEDs to pins 0 through 3 as shown in the TOGGLE command descrip-
    ' tion in the manual and run this program. The TOGGLE command will treat
    ' you to a light show. You may also run the demo without LEDs. The Debug
    ' window will show you the states of pins 0 through 3.

    ' {$STAMP BS1}
    ' {$PBASIC 1.0}

    SYMBOL  thePin          = B0            ' pin 0 - 3

    Setup:
      DIRS = %1111                          ' make LEDs output, low

    Main:
      FOR thePin = 0 TO 3                   ' loop through pins
        TOGGLE thePin                       ' toggle current pin
        DEBUG CLS, %PINS                    ' show on Debug
        PAUSE 100                           ' short delay
      NEXT
      GOTO Main                             ' repeat forever
      END

NOTE: The example below is written for the BS2 and will run on any of the BS2-family modules. Modify the $STAMP directive (as required) before downloading to the BS2e, BS2sx, BS2p, BS2pe, or BS2px.

    ' TOGGLE.BS2
    ' Connect LEDs to pins 0 through 3 as shown in the TOGGLE command descrip-
    ' tion in the manual and run this program. The TOGGLE command will treat
    ' you to a light show. You may also run the demo without LEDs. The Debug
    ' window will show you the states of pins 0 through 3.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    thePin          VAR     Nib             ' pin 0 - 3

    Setup:
      DIRA = %1111                          ' make LEDs output, low

    Main:
      DO
        FOR thePin = 0 TO 3                 ' loop through pins
          TOGGLE thePin                     ' toggle current pin
          DEBUG HOME, BIN4 OUTA             ' show on Debug
          PAUSE 250                         ' short delay
        NEXT
      LOOP                                  ' repeat forever
      END

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012