Timeline for Why doesn't this debounce function work?
Current License: CC BY-SA 3.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 14, 2016 at 16:51 | comment | added | gbulmer | @Jasen - Yes, that would be better. C++ classes are a bit verbose (I like to write Go) but a simple class would do, or a struct if there were several buttons to handle. | |
| Jan 14, 2016 at 9:27 | comment | added | Jasen |
@gbulmer or use static variables private to debounce()
|
|
| Jan 14, 2016 at 2:34 | comment | added | Dave Tweed | No, it isn't entirely pointless, because you can use it as an additional local variable inside the function. You can think of it as the caller initializing that variable for you, but then you can update it as needed while the function executes. | |
| Jan 14, 2016 at 2:18 | comment | added | Dallin | Thank you for your answer @Dave, I think I'm starting to understand. But quick question, what do you mean by "an assignment to a function parameter does NOT update the corresponding variable in the callers environment"? Does this mean assigning a variable to a function parameter is pointless? | |
| Jan 13, 2016 at 23:06 | comment | added | gbulmer |
Beat me to it! +1 for "It worked perfectly" is probably an overstatement. Yes, you saw the LED change when you pressed the button, but that doesn't mean it was getting debounced.. A quick (possible) fix is to remove the parameters to debounce() and keep the state in global variables. A bit messy, but more useful than broken.
|
|
| Jan 13, 2016 at 22:58 | history | answered | Dave Tweed | CC BY-SA 3.0 |