Ticker to set a boolian = true, possible?

I'm using Ticker to schedule tasks.
Setting a boolean to TRUE, and then in the loop check if the flag is true to then execute the code.
This to avoid eventual crashes that (if I understood correctly) can occur if a piece of code takes to long to execute and called directly from Ticker.

Code today:

updateLCD_1s.attach_ms(900, updateLCD_1s_Run);    // Update row 0 on display every second

void updateLCD_1s_Run() {            // Update row 0 on display every second
updateLCD_1s_Flag = true;
}

Any way to replace that with something similar to this to reduce the amount of crappy code?:

updateLCD_1s.attach_ms(900, updateLCD_1s_Flag = true);   // This does not work!

I would not recommend using a library for the simple task of calling a function every second. Just do it with millis() and blink without delay methods (covered exhaustively in literally thousands of guides and tutorials) like everyone else does.

Using libraries for simple tasks like that is generally not great practice on embedded systems.

Untested, but this should work:

updateLCD_1s.attach_ms(900, []{ updateLCD_1s_Flag = true; });

https://en.cppreference.com/w/cpp/language/lambda

Pieter

Thanks PieterP!!!
It works great!!!
Now I can simplify my code quite a bit!

DrAzzy, yes I do not doubt millis is a good choice. But in this case I have many things to be scheduled in minutes and hours.
But I keep it in mind for further projects!

Personally, I use this Timer class. It's just a wrapper for millis() "blink-without-delay"-style, so it doesn't add any overhead, but it makes for a much cleaner loop function.

I believe this also solves your problem with the boolean flag.

#include <Arduino_Helpers.h>
#include <AH/Timing/MillisMicrosTimer.hpp>
 
Timer<millis> timer = 500; // milliseconds
 
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
}
 
void loop() {
  if (timer) {
    digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
  }
}

https://tttapa.github.io/Arduino-Helpers/Doxygen/d1/dd0/MillisMicrosTimer_8hpp_source.html