//github.com/dibyasn
//Toggling LEDs using millis function
// Define pin numbers for the LEDs
#define LED1_PIN 10 // Pin connected to the first LED
#define LED2_PIN 5 // Pin connected to the second LED
// Variables to store the last time the LEDs were toggled
unsigned long lastToggleTimeLED1 = 0; // Last toggle time for LED1
unsigned long lastToggleTimeLED2 = 0; // Last toggle time for LED2
// Interval times for blinking (in milliseconds)
const unsigned long blinkIntervalLED1 = 500; // Time interval for LED1 blink
const unsigned long blinkIntervalLED2 = 500; // Time interval for LED2 blink
void setup() {
// Set the LED pins as OUTPUT
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
}
void loop() {
// Get the current time in milliseconds since the program started
unsigned long currentTime = millis();
// Toggle LED1 if the interval has passed
if (currentTime - lastToggleTimeLED1 >= blinkIntervalLED1) {
lastToggleTimeLED1 = currentTime; // Update the last toggle time for LED1
digitalWrite(LED1_PIN, !digitalRead(LED1_PIN)); // Toggle LED1's state
}
// Toggle LED2 if the interval has passed
if (currentTime - lastToggleTimeLED2 >= blinkIntervalLED2) {
lastToggleTimeLED2 = currentTime; // Update the last toggle time for LED2
digitalWrite(LED2_PIN, !digitalRead(LED2_PIN)); // Toggle LED2's state
}
}