const int LED1 = 23; // GPIO pin connected to LED1
const int LED2 = 19; // GPIO pin connected to LED2
const int LED3 = 18; // GPIO pin connected to LED3
unsigned long previousLed1Millis = 0; // Variable to store the last time LED1 was updated
unsigned long previousLed2Millis = 0; // Variable to store the last time LED2 was updated
unsigned long previousLed3Millis = 0; // Variable to store the last time LED3 was updated
const long led1Interval = 1000; // Interval at which to toggle LED1 (milliseconds)
const long led2Interval = 2000; // Interval at which to toggle LED2 (milliseconds)
const long led3Interval = 3000; // Interval at which to toggle LED3 (milliseconds)
bool led1State = LOW; // Initial state of LED1
bool led2State = LOW; // Initial state of LED2
bool led3State = LOW; // Initial state of LED3
void setup() {
// Initialize GPIO pins as outputs
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
// Toggle LED1 state every 1 second
if (currentMillis - previousLed1Millis >= led1Interval) {
previousLed1Millis = currentMillis;
led1State = !led1State;
digitalWrite(LED1, led1State);
}
// Toggle LED2 state every 2 seconds
if (currentMillis - previousLed2Millis >= led2Interval) {
previousLed2Millis = currentMillis;
led2State = !led2State;
digitalWrite(LED2, led2State);
}
// Toggle LED3 state every 3 seconds
if (currentMillis - previousLed3Millis >= led3Interval) {
previousLed3Millis = currentMillis;
led3State = !led3State;
digitalWrite(LED3, led3State);
}
}