interruption

Hello
I try to create interruptions with the ESP32.
Do you think there is a more straight forward method than mine?
I m looking for something like Flexitimer function.
Thanks

volatile int interruptCounter;
int totalInterruptCounter;
#define led_2 2
boolean ledstate=HIGH;
hw_timer_t * timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
 
void IRAM_ATTR onTimer() {
  portENTER_CRITICAL_ISR(&timerMux);
  interruptCounter++;
  portEXIT_CRITICAL_ISR(&timerMux);
 
}
 
void setup() {
 
  Serial.begin(115200);
 
  timer = timerBegin(0, 4640, true);
  timerAttachInterrupt(timer, &onTimer, true);
  timerAlarmWrite(timer, 32000, true);
  timerAlarmEnable(timer);
pinMode(led_2,OUTPUT);
}

 void loop() {
  if (interruptCounter > 0) {
 
    portENTER_CRITICAL(&timerMux);
    interruptCounter--;
   portEXIT_CRITICAL(&timerMux);
 
    totalInterruptCounter++;

 
    Serial.print("An interrupt as occurred. Total number: ");
    Serial.println(totalInterruptCounter);
 digitalWrite(led_2,ledstate);
 ledstate=!ledstate;
 
}
}