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.
' COUNT.BS2 ' Connect an active-low button circuit shown to pin P0 of the BS2. The ' DEBUG screen will prompt you to press the button as quickly as possible ' for a 1-second count. When the count is done, the screen will display ' your "score," the total number of cycles registered by COUNT. Note that ' this score will almost always be greater than the actual number of presses ' because of switch contact bounce. ' {$STAMP BS2} ' {$PBASIC 2.5} PushBtn PIN 0 ' pushbutton on P0 #SELECT $STAMP #CASE BS2, BS2E DurAdj CON $100 ' / 1 #CASE BS2SX DurAdj CON $280 ' / 0.400 #CASE BS2P, BS2PX OneSec CON $37B ' / 0.287 #CASE BS2PE OneSec CON $163 ' / 0.720 #ENDSELECT Capture CON 1000 ' 1 second cycles VAR Word ' counted cycles Main: DO DEBUG CLS, "How many times can you press the button in 1 second?", CR PAUSE 1000 DEBUG "Ready, set... " PAUSE 500 DEBUG "GO!", CR COUNT PushBtn, (Capture */ DurAdj), cycles DEBUG CR, "Your score: ", DEC cycles, CR PAUSE 3000 DEBUG "Press button to go again." DO : LOOP UNTIL (PushBtn = 0) ' wait for button press LOOP END
BASIC Stamp Help Version 2.5.4
Copyright © Parallax Inc.
8/8/2012