⏱️ Updates timing macro
This commit is contained in:
@@ -5,14 +5,14 @@
|
|||||||
|
|
||||||
#define UNIQUE_VAR(base) CONCAT(base, __LINE__)
|
#define UNIQUE_VAR(base) CONCAT(base, __LINE__)
|
||||||
|
|
||||||
#define EXECUTE_EVERY_N_MS(n, code) \
|
#define EXECUTE_EVERY_N_MS(n, code) \
|
||||||
do { \
|
do { \
|
||||||
static volatile unsigned long UNIQUE_VAR(lastExecution_) = ULONG_MAX; \
|
static volatile unsigned long UNIQUE_VAR(lastExecution_) = 0; \
|
||||||
unsigned long currentMillis = millis(); \
|
unsigned long currentMillis = millis(); \
|
||||||
if (currentMillis - UNIQUE_VAR(lastExecution_) >= n) { \
|
if (UNIQUE_VAR(lastExecution_) == 0 || currentMillis - UNIQUE_VAR(lastExecution_) >= n) { \
|
||||||
code; \
|
code; \
|
||||||
UNIQUE_VAR(lastExecution_) = currentMillis; \
|
UNIQUE_VAR(lastExecution_) = currentMillis; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TIME_IT(code) \
|
#define TIME_IT(code) \
|
||||||
|
|||||||
Reference in New Issue
Block a user