// Withou usin delay
int ledState = 0; // Variable to keep track of the current LED state
unsigned long previousMillis = 0; // Variable to store the last time the LED was updated
const long interval = 500; // Interval at which to blink (milliseconds)
void setup() {
// Set the pin modes
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis(); // Get the current time
if (currentMillis - previousMillis >= interval) {
// Save the last time you blinked the LED
previousMillis = currentMillis;
// Turn off all LEDs
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
// Update the LED state
if (ledState == 0) {
digitalWrite(13, HIGH);
ledState = 1;
} else if (ledState == 1) {
digitalWrite(12, HIGH);
ledState = 2;
} else if (ledState == 2) {
digitalWrite(11, HIGH);
ledState = 0;
}
}
}