I have this code that I am trying to make as a good working example. The code works fine, the only thing that's missing that i haven't been able to figure out is where and what to add to the code to make the numbers increment/decrement faster when the button is held down.
checkUp and checkDown are pretty much the same, so I'll deal only with checkUp.
In the checkUp function, when you test if(up_buttonState != up_lastButtonState) you check if the button state changed and act accordingly. But you don't do anything if the state didn't change, which is what you want to catch.
So you need to add a 'else' there.
The delay(50) is ok for debounce, and you can decrease it down to 20 or 30 (to be tested). If you want to increment faster, also decrease that delay in the 'else' you'll be adding.
Oh man I am not sure what to do there. I bought this arduino kit about 7 months ago to start learning how to do some cool things with this board. I started using it finally over the weekend, but when I got to the button counter example I didn't think it was a practical example.
It doesn't make sense to have to push the button 100 times to count to 100 or to decrement back to zero. I wanted to add that missing piece in there so I could have an example that I could eventually use when I need it.
Imagine setting the time on your watch and you have to keep pressing the button until you get the time correct, I think thats how it was in the old days but not anymore.
The only piece to me thats missing in the code is to hold the button down and have it continue counting without pressing over and over.
That worked pretty good. Only issue I have is when I press the button one time the numbers double up like 0,2,4,6,8,10 etc. When i hold down the button down for a while the numbers go in sequence like it should.
You may be seeing the effects of bounce. You might want to qualify the button presses with a debounce-on-change call and pass the results of that to checkUp() as a parameter.
JohnRandalls:
Damn dude, I just tried it and that was SUPER easy.
There's a library for pretty much anything you might want to try on an Arduino, it seems. Lucky for us, we're usually not the first people to try a thing, and some kind soul published their wisdom in a library.
Have a look (for example) in the Playground to see what folk have done previously. There's quite a lot of button-related stuff there.