Count command Question

biggmacattack

New Member
Hi... I am using an 08m to count the number times a button is pressed in a specific amount of time (more than 5X). Then depending on the amount of times the button is pressed have the chip illuminate an led. I can't seem to get this to work in the simulator.

So, is this operator error or will the simulator not count the number of inputs?

Thanks

Code:
Main:
count 3, 5000, b1 'counts the button presses on pin3
If B1 > 5 then ledon 'reads b1 with an if/then 
goto main

ledon:
High 1 'led on
pause 500 
Low 1 'led off
goto main
 

Michael 2727

Senior Member
Use the Generic Button in the SIM, this will increment b1 x 50.
To bring up the Variables window use the arrow, bottom right
corner of the SIM window.
 

westaust55

Moderator
While noting that you are trying this in the simulator at present, for actual use in the PICAXE switch debounce is an issue.

When looking at a switch input directly, there is also a need to consider switch debounce to prevent unwanted extra counts.
Have a look at Manual section 3 page 26 for information about this.

The BUTTON command detailed in Manual 2 page 26 is a better option as this automatically debounces the switch presses. You will need to have a loop using the Timer commands to loop for the 4 seconds. Have a loop at Jeremy’s suggestion for a delay here:
http://www.picaxeforum.co.uk/showthread.php?t=10153
 

Michael 2727

Senior Member
The Hardware solution to switch debounce is to place a small
capacitor 0.1µf or 100n across the switch contacts.
This works better than 95% of the time unless you have a really bad switch, try 0.22µf - 220n.
 

biggmacattack

New Member
Michael and westaust55

Thanks to both of you for the input. I was aware of the switch bounce but had no idea of correcting it using a cap or the button command. To tell you the truth I was going to try to correct that on the fly. :)

You just saved me half a bottle of aspirin I'm sure.

I've got everything on the protoboard right now and will try both suggestions. Thanks again.
 
Top