Trying to turn button code into a function so it works with multiple buttons

Integers are passed by value. The function gets a COPY of the value and can't change the variable being passed. For lastState, currentState, pressedTime, releasedTime, isPressing, isShortDetected, and isLongDetected you probably want to use references so the function can change the values of those variables.

void buttonPressDetection(const int BUTTON_PIN, int &lastState, int &currentState, unsigned long &pressedTime, unsigned long &releasedTime, bool &isPressing, bool &isShortDetected, bool &isLongDetected) {
1 Like