some issues:
* it seems to be an infinite main loop. While this is possible.... it´s a waste of 100% processing power. The processor can´t do anything else.
* in the 3rd box you set LastState=CurrentState; in the next box you do an "IF LastState == CurrentState" ... there never can be "NO"
* you don´t initialize count. Let´s guess it starts with 0. In box 5 you increment it. Now it´s 1. In the next box you do an "IF count > 5". --> the answer is: NO. Then you set it to 0 again. The value of count can never be 2......is this what you want?
* in the bottom box you say "Button pressed". This is not true. It can also be "button released"
... and when you have a command "button pressed" in your code, then you always need code for anything else than "button pressed".
* count will be incremented every loop.... until rollover
******
I recomend to use a sheet of paper an a pencil and go step by step through your chart. In each loop write down all the values, do all the compares...
Do you want the button considered pressed if it just meets the count or
do you want to consider it a legit button once released, bounced out,
as well ?
Do you want the button considered pressed if it just meets the count or
do you want to consider it a legit button once released, bounced out,
as well ?
I am not fully confident in the basics right now. I see there are the two case, pressed and released. I think When we press or release the button both the time switch will debounce for few millisecond.
I will check the push-button value every 10 mS: I will accept a change only if the new value remains stable five times,
Take a look at this, various methods, algorithms as well.
Attached.
Note I see folks using various delays. I had a case where I measured > 300 mS in a
part, crappy to say the least. More often I see folks using 100 mS for de-bounce design
work.
Bouncing time depends on the switch. Older, high current, spring loaded tend to higher bouncing time.
Modern switches should not bounce more than 10ms.
For inputs when one wants a value to count up, one get almost 10 pulses per second. So in ideal case 50ms / 50ms.
I usually go to 20ms debouncing time.
Debounce time, if you can, play it safe, use 100 mS or more. Some use short time on
bounce in, and longer time on bounce out. That way key task is triggered rapidly, and
bounce out covers any longer poor switch bouncing times in and out.
If its a rapid switch rep rate, like used on industrial processes, then qualify the component
by looking at DSO captures of bounce.
Play it safe, especially in human safety applications.