Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
LICENSE
README.md
RecurringTask.h
library.json

README.md

Recurring Task

When you make something with Arduino the following snipped should be very familiar to you.

void loop() {
  static unsigned long last = 0;

  unsigned long now = millis();
  if (now > (last + 1000)) {
    Serial.println("This line should be printed every second");
    last = now;
  }
}

It's widely used when you want to execute some task with period different from the main loop.

After writing the same code multiple times I extracted small but very semanticaly efficient library called RecurringTask. The idea and usage is very simple - you just define the period of execution in milliseconds or number of loop iterations and the library does the rest:

#include <RecurringTask.h>

void loop()
{
    RecurringTask::interval(1000, []() {
        Serial.println("This line should be printed every second");
    });
}
You can’t perform that action at this time.