BASIC stamp manual v2.2
COUNT – BASIC Stamp Command Reference
Page 150 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
width (on the BS2). Refer to Table 5.6 for data on other BASIC Stamp
models.
If you use COUNT on slowly changing analog waveforms like sine waves,
you may find that the value returned is higher than expected. This is
because the waveform may pass through the BASIC Stamp module’s logic
threshold slowly enough that noise causes false counts. You can fix this by
passing the signal through a Schmitt Trigger, like one of the inverters of a
74HCT14. Or, you may use the BS2px’s built-in Schmitt-Trigger pin
property; see the CONFIGPIN section beginning on page 143 for details.
Demo Program (COUNT.bs2)
' COUNT.bs2
' Connect an active-low button circuit shown in the BUTTON command
' description 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
DurAdj CON $37B ' / 0.287
#CASE BS2PE
DurAdj 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... "
All
2
NOTE: This example program can be
used with all BS2 models. This program
uses conditional compilation techniques;
see Chapter 3 for more information.