// Pin definitions
const int staticLEDs[] = {2, 3, 4, 5}; // Static LEDs on D2, D3, D4, D5
const int flashingLED = A1; // Flashing LED on A1
const int flickerLEDs[] = {A2, A3, A4, A5}; // Flicker LEDs on A2, A3, A4, A5
// Timing for the flashing LED
const int flashOnTime = 150; // On time in ms
const int flashOffTime1 = 150; // Off time in ms (first interval)
const int flashOffTime2 = 800; // Off time in ms (second interval)
// Variables for timing
unsigned long previousMillisFlashing = 0; // For flashing LED
unsigned long previousMillisFlicker[4]; // For each flickering LED
// State for the flashing LED
int flashState = 0;
// Setup
void setup() {
// Initialize static LEDs
for (int i = 0; i < 4; i++) {
pinMode(staticLEDs[i], OUTPUT);
digitalWrite(staticLEDs[i], HIGH); // Turn on static LEDs
}
// Initialize flashing LED
pinMode(flashingLED, OUTPUT);
digitalWrite(flashingLED, LOW); // Start with the LED off
// Initialize flicker LEDs
for (int i = 0; i < 4; i++) {
pinMode(flickerLEDs[i], OUTPUT);
previousMillisFlicker[i] = millis(); // Start timing for each flicker LED
}
}
// Main loop
void loop() {
// Handle the flashing LED
handleFlashingLED();
// Handle the flickering LEDs
for (int i = 0; i < 4; i++) {
handleFlickerLED(i);
}
}
// Function to handle the flashing LED
void handleFlashingLED() {
unsigned long currentMillis = millis();
switch (flashState) {
case 0: // Off for the first interval
if (currentMillis - previousMillisFlashing >= flashOffTime1) {
flashState = 1;
previousMillisFlashing = currentMillis;
digitalWrite(flashingLED, HIGH); // Turn the LED on
}
break;
case 1: // On for 150ms
if (currentMillis - previousMillisFlashing >= flashOnTime) {
flashState = 2;
previousMillisFlashing = currentMillis;
digitalWrite(flashingLED, LOW); // Turn the LED off
}
break;
case 2: // Off for the second interval
if (currentMillis - previousMillisFlashing >= flashOffTime2) {
flashState = 3;
previousMillisFlashing = currentMillis;
digitalWrite(flashingLED, HIGH); // Turn the LED on
}
break;
case 3: // On for 150ms again
if (currentMillis - previousMillisFlashing >= flashOnTime) {
flashState = 0;
previousMillisFlashing = currentMillis;
digitalWrite(flashingLED, LOW); // Turn the LED off
}
break;
}
}
// Function to handle the flickering LEDs
void handleFlickerLED(int index) {
unsigned long currentMillis = millis();
if (currentMillis - previousMillisFlicker[index] >= random(50, 300)) { // Random interval
int brightness = random(100, 256); // Random brightness between 100 and 255
analogWrite(flickerLEDs[index], brightness);
previousMillisFlicker[index] = currentMillis;
}
}