Teensy 4.x timer interrupt example using TimerTree
void myTimerInterrupt() {
// TODO Your code goes here
// The following functions may be useful here:
// Timer3.start(); // Start counting & clear counter
// Timer3.stop(); // => stop counting but do not clear counter
// Timer3.restart(); // => clear counter
// Timer3.resume(); // => Start, without clearing counter
}
void setup()
{
Timer3.initialize(20000);
Timer3.attachInterrupt(myTimerInterrupt);
Timer3.start();
}