Skip to content

Instantly share code, notes, and snippets.

@bathoryr
Last active November 14, 2020 17:30
Show Gist options
  • Save bathoryr/5530205af8d7179b59a964c5f4adc523 to your computer and use it in GitHub Desktop.
Save bathoryr/5530205af8d7179b59a964c5f4adc523 to your computer and use it in GitHub Desktop.
Macro to simplify periodic function call by regular interval in Arduino loop()
#define CALL_LOOP(TIME, FUNC) {static unsigned long cnt_##FUNC_##TIME_counter;\
if (millis() - cnt_##FUNC_##TIME_counter > (TIME)) {\
cnt_##FUNC_##TIME_counter = millis();\
FUNC();}\
}
void TestFunc()
{
}
void loop()
{
CALL_LOOP(5000, TestFunc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment