#include <TimerOne.h> // Ensure this library is correctly installed
const int LED_PIN = 13; // Built-in LED on most Arduino boards
volatile unsigned long millisCount = 0;
bool ledState = LOW;
void setup() {
pinMode(LED_PIN, OUTPUT); // Initialize LED pin as output
Timer1.initialize(1000); // Initialize Timer1 to trigger every 1000 microseconds (1 ms)
Timer1.attachInterrupt(timerISR); // Attach our ISR to the timer
}
void loop() {
// Empty loop as the code is interrupt-driven
}
void timerISR() {
millisCount++;
if (millisCount >= 1000) { // Every 1000 ms (1 second)
millisCount = 0;
ledState = !ledState; // Toggle the LED state
digitalWrite(LED_PIN, ledState); // Write the LED state to the pin
}
}