Verify esp32 Code, IT has no error

#include <Arduino.h>

const int ledPin = 18;     // GPIO pin where the LED is connected
const int buttonPin = 35;  // GPIO pin where the button is connected

volatile bool ledOn = false;  // Flag to track LED state

hw_timer_t * timer = NULL;  // Declare a pointer to the timer object

// Timer interrupt service routine
void IRAM_ATTR onTimer() {
  digitalWrite(ledPin, ledOn ? LOW : HIGH);  // Toggle LED state
  ledOn = !ledOn;
}

void timerSetup() {
  // Create an instance of the timer
  timer = timerBegin(0, 80, true); // Timer 0, prescaler 80, count up
  
  // Attach the ISR function to the timer
  timerAttachInterrupt(timer, &onTimer, true);
  
  // Set the timer to trigger every 500 milliseconds (2000000 microseconds)
  timerAlarmWrite(timer, 2000000, true);
  
  // Start the timer
  timerAlarmEnable(timer);
}

// Button interrupt service routine
void IRAM_ATTR buttonInterrupt() {
  // Turn off the LED
  digitalWrite(ledPin, LOW);
  ledOn = false;
}

void setup() {
  pinMode(ledPin, OUTPUT);                  // LED pin as output
  pinMode(buttonPin, INPUT_PULLUP);         // Button pin as input with pull-up resistor
  
  attachInterrupt(digitalPinToInterrupt(buttonPin), buttonInterrupt, FALLING);  // Attach interrupt on falling edge (button press)
  
  // Start LED blinking
  timerSetup();
}

void loop() {
  // Other code in loop, if any
}

LED Is continous ON , it is not blinking, there are no errors in the code.

I can't help with ESP32 related stuff.

Are you using an Arduino Nano ESP32 or are you using another ESP32?

It is Wifi ESP - WROOM 32 (ESP23 model)
@sterretje

can you tell me if any logical error is there in the code

Then this topic was posted in the wrong forum category

It has been moved to a more generic category to avoid confusion

Which ESP32 core are you using? The timer API changed with ver 3.0. However, since you do not get compile errors I would guess you are on ver 2.x.

I am using pretty much what you have, but the calls meet the new ver 3.0 API, and it works as expected.

i am using ver 2.x, can you please tell me what is the corrections neeed to be done for ver 2.x
@Willem43

Why not upgrade to version 3 instead ?

All this seem to be related to you last FIVE posts including these two
You have me going in circles

i have idea of commads used in version 2.x for esp32 in IDE,
for version 3.x, i need to chane a lot of commands so i am using version 2.x

i am really sorry @jim-p

I did not now the terms and condtons of arduiino forms so for every time i created a new topic.

now i know the rules of creating a new topic so i will not repeat this mistake.

So I'm now confused.
What exactly is the problem?
Which board are you using?
Post your code and a wiring diagram.

My version of your code below pulses the TX led on my board at a 1 sec interval.

I changed your TimerSetup function to comply with Ver 3.02 of the ESP core. I also used the TX led and not the NeoPixel which is mounted on my board (ESP32 S3). Those, I think, are the only changes I made. I did not connect and check the button part of your sketch.

#include <Arduino.h>

//const int ledPin = 18;      // GPIO pin where the LED is connected
#define ledPin  43          // Pulsing the TX led
const int buttonPin = 35;   // GPIO pin where the button is connected

volatile bool ledOn = false;  // Flag to track LED state

hw_timer_t * timer = NULL;  // Declare a pointer to the timer object

// Timer interrupt service routine
void IRAM_ATTR onTimer() {
  digitalWrite(ledPin, ledOn ? LOW : HIGH);  // Toggle LED state
  ledOn = !ledOn;
}

void timerSetup() {
  // Create an instance of the timer
//  timer = timerBegin(0, 80, true); // Timer 0, prescaler 80, count up
  // Set timer frequency to 1Mhz
  timer = timerBegin(1000000);
  
  // Attach the ISR function to the timer
//  timerAttachInterrupt(timer, &onTimer, true);
  // Attach onTimer function to our timer.
  timerAttachInterrupt(timer, &onTimer);

  // Set alarm to call onTimer function every second (value in microseconds).
  // Repeat the alarm (third parameter) with unlimited count = 0 (fourth parameter).
  timerAlarm(timer, 1000000, true, 0);
  
  // Set the timer to trigger every 500 milliseconds (2000000 microseconds)
//  timerAlarmWrite(timer, 2000000, true);
  
  // Start the timer
//  timerAlarmEnable(timer);
}

// Button interrupt service routine
void IRAM_ATTR buttonInterrupt() {
  // Turn off the LED
  digitalWrite(ledPin, LOW);
  ledOn = false;
}

void setup() {
  pinMode(ledPin, OUTPUT);                  // LED pin as output
  pinMode(buttonPin, INPUT_PULLUP);         // Button pin as input with pull-up resistor
  
  attachInterrupt(digitalPinToInterrupt(buttonPin), buttonInterrupt, FALLING);  // Attach interrupt on falling edge (button press)
  
  // Start LED blinking
  timerSetup();
}

void loop() {
  // Other code in loop, if any
}

NB. You sure you have the LED pin correct?

Thanks for the reply, I will check it @Willem43

sorry to confuse to. @jim-p.
thank for taking intrest in my problem,
by the way the solution was received.

Once again thank you.

So you are back to using 3.0.2?