I'm trying to understand why the second millis() timer does not work as I would expect. Is there some encapsulation that I don't understand while using lambdas? Or maybe I'm just not seeing something!
the second expression in loop() does not print, the first does:
unsigned long timerVal = 0;
void setup()
{
Serial.begin(9600);
Serial.println();
}
void loop()
{
[&timerVal](unsigned long currentTime){if(currentTime - timerVal > 1000UL) {Serial.println("Hello World"); timerVal += 1000UL;}}(millis());
[&timerVal](){if(millis() - timerVal > 1000UL) {Serial.println("Why Not Me?"); timerVal += 1000UL;}};
}
Aucun commentaire:
Enregistrer un commentaire