const int ledPin = 23; // Pin connected to the LED
unsigned long previousMillis = 0; // To store the last time we toggled the LED
const long interval = 500; // Interval for the square wave (500 ms, 1 Hz frequency)
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
}
void loop() {
unsigned long currentMillis = millis(); // Get the current time in milliseconds
// Check if it's time to toggle the LED
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis; // Save the last time we toggled the LED
digitalWrite(ledPin, !digitalRead(ledPin)); // Toggle the LED state
}
}