Software Timers, when the call takes longer than the timer period

I would like to get some clarification on the Software Timer.
I am curious if the code within the callback takes longer than the period time set for the timer.
Will it try to keep calling it, or what will happen.

Lets say this is the code running.

void myTicker(void)

Timer timer(10, myTicker); // Fire myTicker every 10ms

That’s pretty much the reason why you’re not supposed to have any blocking code inside a timer callback. Treat it like an interrupt to set a ‘flag’ for the loop, and act upon it there.

@Moors7, in your scenario, the timer thread will not continue until the callback returns. This will stall all other timers as a consequence. Thus the reason for @Moors7’s statement.

I was thinking in terms it was sort of like an IRQ and I should treat it that way. What throws me off about that concept is the example in the docs for it. They use a Serial.println(count++); in there, IMHO this is not something one should do in an IRQ. So it made me then think what else can you do in there taking up more time before it becomes a problem.
I understand now thanks.


void print_every_second()
static int count = 0;

Timer timer(1000, print_every_second);

void setup()

1 Like