Files
SpotMicroESP32-Leika/esp32/lib/ESP32-sveltekit/Timing.h
T
2024-07-14 23:32:49 +02:00

18 lines
774 B
C

#ifndef TIMING_H
#define TIMING_H
#define CONCAT(a, b) a##b
#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; \
} \
} while (0)
#endif