I realize my question is not precise, so I have a simple contrived example to illustrate better what I am asking.
I am trying to use EVERY_N_SECONDS inside a member function of a class that is invoked in the sketch's loop() method. And this works fine, but when I have two instances of the class, each has its member function called in the loop(), but one instance seems to "win" and the other instance never seems to hit the inside of the EVERY_N_SECONDS block.
For example, the following code produces this output (I expected both a2 and a1 to appear in "a2 is in the EVERY_N_SECONDS loop"):
a1 is in the loop
a1 is in the EVERY_N_SECONDS loop
a2 is in the loop
a1 is in the loop
a1 is in the EVERY_N_SECONDS loop
a2 is in the loop
a1 is in the loop
a1 is in the EVERY_N_SECONDS loop
a2 is in the loop
Here is the code, a silly little program to illustrate the question:
#include <Streaming.h>
#include <FastLED.h>
class A {
public:
String tag;
void loop()
{
Serial << tag << " is in the loop" << endl;
EVERY_N_SECONDS(2) {
Serial << tag << " is in the EVERY_N_SECONDS loop" << endl;
}
}
};
A a1, a2;
void setup() {
Serial.begin(9600);
a1.tag = "a1";
a2.tag = "a2";
}
void loop() {
a1.loop();
a2.loop();
FastLED.delay(5000);
}