MsTimer2 question

I’m using 328p and IDE 018.

The LED (13) should blink at start and only once again after 5 seconds.
But the LED does not switch off after 5 sec.
What’s wrong with this code ?

// blink once on start and once after 5 sec

#include <MsTimer2.h>

void setup() {
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
  flash();

  MsTimer2::set(5000, flash); 
  MsTimer2::start();
}

void loop() {
}

void flash() {

  digitalWrite(13, HIGH);
  delay(500);
  digitalWrite(13, LOW);
    
  MsTimer2::stop();

}

delay(500) only works if timer0-interrupts are allowed to advance the millisecond-counter. The second call to flash is made from a timer2-interrupt, which blocks other interrupts so it will hang forever in delay(500).

Thank You ! Would this wotk if i disable only timer2-interrupt ?

not good idea, i assume. any suggestion ?

disabling timer2 interrupt is what MsTimer2::stop() does.
What you could do is have the function you specify in MsTimer2::set() only set a global (and volatile) flag to true. Then you could use, e.g.

void loop() {
    if (flag) {
      flag = false;
      digitalWrite(13, HIGH);
      delay(500);
      digitalWrite(13, LOW); 
      // possibly call MsTimer2::stop() here if the flash is only to be run once
    }
}

ok, thx :)