So, I have 3 buttons to a arduino. I want to detect the button press on the 3 of them.
For that, i've created a function:
int OnKeyPress (int port) {
int LastState, BeginState, r;
r = 0;
BeginState = digitalRead(port);
if (BeginState != LastState) {
if (BeginState == 1) r = 1 ;
}
delay(5);
LastState = BeginState;
return r;
}
I want to instantiate 3 instances of this code, separately and they have to retain this variables int LastState, BeginState, r;
for each button, and the next time the function runs on the loop, the variables are the same of when they ran last time.
Just, how?
class
. tutorialspoint.com/cplusplus/cpp_classes_objects.htm