Button Action

Here is my code to replace what’s there now if you just want the input the do something when on or off (not momentary like it is by default). This calls the press and long-press macros.

void handleButton() 
{
#ifdef BTNPIN
  if (!buttonEnabled) return;
  if (digitalRead(BTNPIN) == LOW) { //pressed
    if (!buttonPressedBefore){
      buttonPressedBefore = true;
      applyMacro(macroButton); // input on
    }
    }
  else if (digitalRead(BTNPIN) == HIGH && buttonPressedBefore) //released
  {
    applyMacro(macroLongPress);
    buttonPressedBefore = false;
  }
#endif
}

Thanks for sharing! What chunk of code should I replace and where?

No need these days. Just set the “button” as a switch. :wink: