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 = 600; // Initial delay time in milliseconds (2 seconds)
int minDelayTime = 100; // 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() {
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
}
// 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 >= 2000) {
decreasing = true; // Switch to decreasing mode again
}
}
}