Timeline for Understanding Debounce code
Current License: CC BY-SA 4.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 15, 2020 at 3:41 | comment | added | jsotola | @thegoodhunter-9115 you can do a simple test ... write a sketch that, in setup(), prints the value of millis() and sets a counter to zero .... in loop() increments the counter ... when the counter reaches 1000, prints millis() again .... that will give you an idea of approximately how long 1000 iterations of loop() take | |
Sep 15, 2020 at 3:36 | comment | added | jsotola | @thegoodhunter-9115 thank you for the explanation of your misunderstanding ... i learned something from you today ... i now know that the loop() execution time can be the source of confusion | |
Sep 15, 2020 at 2:55 | vote | accept | Community Bot | ||
Sep 15, 2020 at 0:36 | comment | added | jsotola | @thegoodhunter-9115 seriously think about what i said about the light and the stopwatch .... what would you do with the stopwatch if the light turned on or turned off? | |
Sep 14, 2020 at 23:10 | comment | added | DataFiddler |
If loop takes a microsecond and bouncing takes two milliseconds, reading will be evaluated 2000 times in those 2 ms, and change a couple of times during this period. Only if is stable for 50 ms (you got nearly an infinite number of the same reading values) you accept that as a new debounced button state
|
|
Sep 14, 2020 at 23:03 | comment | added | Delta_G | Why would it always be 0? It will be whatever the pin reads. Every time loop repeats it reads the pin again and you get a new reading. We could check lastButtonState or reading, they will be the same at that point in the code. If they aren't the same then lastDebounceTime gets set to the current time and we don't enter that second if statement. | |
Sep 14, 2020 at 22:53 | history | answered | DataFiddler | CC BY-SA 4.0 |