I want to use external push button to setup a variable in my microcontroller. I have two button: up and down. I use a debounce algorithm to assure that when I push the button one time only, the variable is incremented one time only...
But the problem for now is when I keep the button pushed, the variable increments at the rate of my debounce cycle time. I want to increment the variable very rapidly if I keep the button pushed for more than 2 seconds (and as well that I keep the button pushed when it's is increment very rapidly). And, before the 2 seconds, I don't want that the variable be incremented.
Maybe someone have an idea or refer me on some web site?
In my previous project, i used a counter to count how many time the debounce cycle time has passed. I checked the counter against a limit value before incrementing the variable. The limit value is placed in another register so that it can be modified. At first placed a long enough limit, and gradually decreased the limit to get a 'getting faster' effect.
Switch pushed ?
- No --> loop
- Yes --> x,xx sec. debounce tempo, Increment variable, when timing variable oveflowed, goto :
x,xx sec. counter
Switch still pushed ?
- No, goto...
- Yes, Is counter variable overflowed ?
- No, continue to count
- Yes, increment variable, and loop.