const int numLEDs = 10; // Number of LEDs in the strip
const int ledPins[numLEDs] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // Pins connected to LEDs
int delayTime = 500; // Initial delay time in milliseconds (2 seconds)
int minDelayTime = 0; // Minimum delay time (250 milliseconds)
int delayStep = 100; // Step to decrease or increase delay time
bool decreasing = true; // To keep track of delay decreasing/increasing
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 baud rate
Serial.println("LED Chase Initialized");
for (int i = 0; i < numLEDs; i++) {
pinMode(ledPins[i], OUTPUT); // Set each LED pin as output
digitalWrite(ledPins[i], LOW); // Turn off all LEDs initially
}
}
void loop() {
// LED Chase forward
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH); // Turn on the current LED
delay(delayTime); // Delay for the current delayTime
digitalWrite(ledPins[i], LOW); // Turn off the current LED
}
// LED Chase backward
for (int i = numLEDs - 1; i >= 0; i--) {
digitalWrite(ledPins[i], HIGH); // Turn on the current LED
delay(delayTime); // Delay for the current delayTime
digitalWrite(ledPins[i], LOW); // Turn off the current LED
}
// Print current delay time to serial monitor
Serial.print("Current delay time: ");
Serial.println(delayTime);
// Update delay time
if (decreasing) {
delayTime -= delayStep; // Decrease delay time
if (delayTime <= minDelayTime) {
decreasing = false; // Switch to increasing mode
}
} else {
delayTime += delayStep; // Increase delay time
if (delayTime >= 600) {
decreasing = true; // Switch to decreasing mode again
}
}
}