Shop OBEX P1 Docs P2 Docs Learn Events
the ''count'' instruction — Parallax Forums

the ''count'' instruction

ArchiverArchiver Posts: 46,084
edited 2003-02-03 18:33 in General Discussion
>Hi. I need to count the number of times a switch closes during a
>whole day. Is the count instruction the wrong one to use? Is it
>possible to run the count for the whole day or would the period just
>be too long? Thanks loads for anyhelp.


No, the COUNT instruction is limited to 65.535 seconds on the BS2.
You could conceivably string together COUNTs in a loop. Be sure you
debounce your switch inputs with an RC circuit, otherwise COUNT will
respond to every bounce.


'{$PBASIC 2.5}
total var word
subtotal var word
minutes var word
do
total=0
for minutes=0 to 1439 ' 1440 minutes per day
count 0,60,subtotal ' one minute at a time
total=total+subtotal
next
debug dec,total,cr
loop


But that might not be the best way to do it. The Stamp can't do
anything else while the COUNT instruction is executing.

If the switch closes infrequently, you can poll an input pin. I have
examples for a rain gage and an anemometer posted at
<http://www.emesys.com/OWL2face.htm#rain>
<http://www.emesys.com/BS2fsm.htm#counter>


Last resort, most reliable, use an external counter chip.
Sign In or Register to comment.