Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
32 lines (26 sloc) 568 Bytes
#pragma once
namespace RecurringTask
{
template <typename F>
void every(int iterations, const F &lambda)
{
static int iterationsCount = 0;
iterationsCount++;
if (iterationsCount >= iterations)
{
lambda();
iterationsCount = 0;
}
}
template <typename F>
void interval(unsigned long milliseconds, const F &lambda)
{
static unsigned long lastExecution = 0;
unsigned long now = millis();
if (now > (lastExecution + milliseconds))
{
lambda();
lastExecution = now;
}
}
} // namespace RecurringTask
You can’t perform that action at this time.