I was wondering about writing my own denouncing function. If I pass the variable that holds the button state to a function, have the function read the variable, wait, then read it again...Is Arduino going to read that variable in real time or is the value frozen when it gets passed to the function? Thanks.
Who are you going to denounce?
What did they do?
Read up on functions here: https://www.arduino.cc/en/Reference/FunctionDeclaration
See if that answers your question. If not, come back with what you don't understand.
If I pass the variable that holds the button state to a function, have the function read the variable, wait, then read it again
So, you want to pass HIGH or LOW to a function, and have the function compare the value passed in to HIGH, wait a while, and compare the value passed in to HIGH again.
What are the odds that one compare will return a different result from the other one? A snowball under an electric blanket in front of a space heater in hell has a better chance.
jarrod0987:
If I pass the variable that holds the button state to a function, have the function read the variable, wait, then read it again...Is Arduino going to read that variable in real time or is the value frozen when it gets passed to the function?
If you want the function to be able to act on the current state of the button, you'll have to read the state of the input pin again. it doesn't automatically update any variable with the current state of the input pin.
Typically this is done by passing the pin number instead of the button state, and the function can do a digitalRead(pinNumber) whenever it needs to check the pin state.
Jimmus:
Typically this is done by passing the pin number instead of the button state, and the function can do a digitalRead(pinNumber) whenever it needs to check the pin state.
But then why bother? If you’ve static state variables in the function (last press time and last known state), you then need a new function for each button.
A class is the right approach, the functions contained in an object... unless we are talking about a single button.
AWOL:
Who are you going to denounce?
What did they do?
I think he means to be denouncing autocorrect - it always changes debounce to denounce.