How do i reset the button count.
I want when i press a button 21 times it will return back to zero button presses.
Can you help me out?
thanks
How do i reset the button count.
I want when i press a button 21 times it will return back to zero button presses.
Can you help me out?
thanks
Or you could try:-
if(button_count == 21) button_count =0;
errm i cant find anything helpful in the link and grumpy mike code is varified.
Ok, well I presumed that you had some code you wanted to do 21 times and then you wanted it to reset. That is what the 'for' code would be used for.
void loop()
{
for (int i=0; i <= 21; i++){
//insert code here
}
}
The code would then repeat 21 times.
Mike's code would just check is the button presses was 21 and then if so, it would reset it which I suppose was what you asked for!
Go Mike! ;D
Mowcius
Mike code is what i want it to do however when i put it in the code wasn't able to be verified. Cheers mike anyway
think i got it working thanks mike ;D
Do make sure you have good debounce on the buttons, or you might miss your reset! If it accidentally counts as two when you're at 20 or something, it'll be 22 pushes. That might have been what happened when you couldn't get it to work the first time, you could do an easy fix by using >= (greater than, or equal to) 21 rather than == (is equal to).
But regardless, if it has to be exactly 21 counts, debounce is a must!
But regardless, if it has to be exactly 21 counts, debounce is a must!
That's a good point, it is something that I had issues with on a recent project when I forgot about it...
Mowcius