diff --git a/esp32/lib/ESP32-sveltekit/Timing.h b/esp32/lib/ESP32-sveltekit/Timing.h index 7616976..c993b0f 100644 --- a/esp32/lib/ESP32-sveltekit/Timing.h +++ b/esp32/lib/ESP32-sveltekit/Timing.h @@ -5,14 +5,14 @@ #define UNIQUE_VAR(base) CONCAT(base, __LINE__) -#define EXECUTE_EVERY_N_MS(n, code) \ - do { \ - static volatile unsigned long UNIQUE_VAR(lastExecution_) = ULONG_MAX; \ - unsigned long currentMillis = millis(); \ - if (currentMillis - UNIQUE_VAR(lastExecution_) >= n) { \ - code; \ - UNIQUE_VAR(lastExecution_) = currentMillis; \ - } \ +#define EXECUTE_EVERY_N_MS(n, code) \ + do { \ + static volatile unsigned long UNIQUE_VAR(lastExecution_) = 0; \ + unsigned long currentMillis = millis(); \ + if (UNIQUE_VAR(lastExecution_) == 0 || currentMillis - UNIQUE_VAR(lastExecution_) >= n) { \ + code; \ + UNIQUE_VAR(lastExecution_) = currentMillis; \ + } \ } while (0) #define TIME_IT(code) \