I have a function set up with a global variable so that it can store its values for later use, but I want to reset it after I've used it. So when I've gotten the value out of my function, I want to set it back, but I can't run a line after the 'return' line if I'm correct. Is there an easy way to reset my variable after the function has run without having to reset the variable after every time I call the function?
Here's what I mean:
// For tracking button presses
int pre_button_state[] = {0, 0, 0, 0, 0}; // This holds the previous button state
int post_button_state[] = {0, 0, 0, 0, 0};// This holds the current button state to compare
int sto_button[] = {-1, -1}; // Store the value of the button being pressed (I want to reset this variable)
int ButtonCheck() {
for (i = 0; i < 4; i++) { // Checks current button reads
post_button_state[i] = digitalRead(button_pin[i]);
}
for (i = 0; i < 4; i++) { // This is where the buttons are checked for consistency
if (post_button_state[i] != pre_button_state[i]) {
if (sto_button[0] == -1) {
sto_button[0] = i;
} else {
sto_button[1] = i;
}
}
}
return (4*sto_button[0])+sto_button[1]; // Fake array (This is where I want to reset it with int sto_button[] = {-1, -1};)
}