Main Site Documentation

Switch Debounce


#1

How is the gpiopin.DebounceTimeout implemented ? How to use it ?


#2
gpio.DebounceTimeout = TimeSpan.FromMilliseconds(100);

#3

internally, what does it do? Is it the length of time between first change to when the ‘actual’ read takes place?


#4

for a start, it will be processor dependent. And second, it should be circuitry and switch hardware dependent. So you’re chasing the wrong thing here - as Dat says, use the debounce timeout for what it is, try it, but it’ll be a compromise and you need to handle it better in your own software once you understand how your switches behave…


#5

That is what I am asking - what is it. On other systems, I handled debounce by starting a timer on first value change and when the time elapsed read the value again and use that as the value of the switch.


#6

that code sounds perfectly feasible here. That is not the switch debounce the processor may expose… I’d just do your own


#7

I did some more testing. I set the debouncetimeout to 2 millisec and it seemd to work


#8

I would expect debounce to ignore any changes that happen in a shorter time than the minimum specified.


#9

What about longer then specified, if I set it to 200ms I don’t get double fire, but when I press the key wait for more then 200ms to release I get double fire, how to avoid that?

DriveMode is InputPullup and checking only on FallingEdge


#10

We have an issue to look into this. Debounce is not perfect today.