# BUTTON Example

Syntax: BUTTON

    ' BUTTON.BS1
    ' Connect an active-low circuit to pin P0 of the BS1. When you press the
    ' button, the DEBUG screen will display an asterisk (*). The program, as
    ' shown below, will print an asterisk at the first button press, then
    ' delay approximately one second (200 x 5 ms PAUSE) before auto-repeating
    ' at a rate of approximately 100 ms (5 x 20 ms).  Feel free to modify the
    ' program to see the effects of your changes on the way BUTTON responds.

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

    SYMBOL  Btn             = 0

    SYMBOL  btnWrk          = B2

    Main:
      ' Try changing the Delay value (255) in BUTTON to see the effect of
      ' its modes: 0 = no delay; 1-254 = varying delays before auto-repeat;
      ' 255 = no auto-repeat (only one action per button press)
      '
      ' The BUTTON instruction will cause the program to branch to
      ' No_Press unless P0 = 0

      PAUSE 5
      BUTTON Btn, 0, 200, 20, btnWrk, 0, No_Press
      DEBUG "*"

    No_Press:
      GOTO Main

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.

    ' BUTTON.BS2
    ' Connect an active-low circuit to pin P0 of the BS2. When you press the
    ' button, the DEBUG screen will display an asterisk (*). The program, as
    ' shown below, will print an asterisk at the first button press, then
    ' delay approximately one second (200 x 5 ms PAUSE) before auto-repeating
    ' at a rate of approximately 100 ms (5 x 20 ms).  Feel free to modify the
    ' program to see the effects of your changes on the way BUTTON responds.

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

    Btn             PIN     0

    btnWrk          VAR     Byte

    Main:
      ' Try changing the Delay value (255) in BUTTON to see the effect of
      ' its modes: 0 = no delay; 1-254 = varying delays before auto-repeat;
      ' 255 = no auto-repeat (only one action per button press)
      '
      ' The BUTTON instruction will cause the program to branch to
      ' No_Press unless P0 = 0

      PAUSE 5
      BUTTON Btn, 0, 200, 20, btnWrk, 0, No_Press
      DEBUG "*"

    No_Press:
      GOTO Main

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012