 const int PIN_BUTTON = 0;
 
 int function = 0;
+
+// Timer related for dimming delays
+unsigned long previousMillis = 0;
+// Milliseconds to wait per cycle for a held command.
+const int waitInterval = 100;
 
 // Associate the PIN_BUTTON GPIO with the ClickButton library
 ClickButton button1(PIN_BUTTON, LOW, CLICKBTN_PULLUP);

#include <Homie.h>

#define FW_NAME "homie-sonoff-touch"
#define FW_VERSION "0.0.10"

/* Magic sequence for Autodetectable Binary Upload */
const char *__FLAGGED_FW_NAME = "\xbf\x84\xe4\x13\x54" FW_NAME "\x93\x44\x6b\xa7\x75";

  // These are repeat events, where the button is being held down.
  // Handle them, but don't reset function back to 0 unless the button is released.
  if ( function < 0 ) {
    if ( millis() - previousMillis >= waitInterval ) {
      previousMillis = millis();
      if ( function == -1 ) {
        Homie.setNodeProperty(buttonNode, "event", "SINGLEHELD", 0);
        Serial.println("SINGLE LONG click");
      }

      if ( function == -2 ) {
        Homie.setNodeProperty(buttonNode, "event", "DOUBLEHELD", 0);
        Serial.println("DOUBLE LONG click");
      }

      if ( function == -3 ) {
        Homie.setNodeProperty(buttonNode, "event", "TRIPLEHELD", 0);
        Serial.println("TRIPLE LONG click");
      }
    }

    // Decide whether the button is being held or not
