int leds[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
int total_leds = sizeof(leds) / sizeof(int);
int ledDelay(100);
int direction = 1;
int currentLED;
unsigned long changeTime;
int effect = 0; // Effect selector (0 = Chase, 1 = Bounce, etc.)
unsigned long lastEffectChangeTime = 0; // To track when to switch effects
unsigned long effectDuration = 6000; // Effect duration in milliseconds (20 seconds)
void setup() {
Serial.begin(9600);
for (int i = 0; i < total_leds; i++) {
pinMode(leds[i], OUTPUT);
}
}
void loop() {
// Execute the current effect
if ((millis() - changeTime) > ledDelay) {
changeTime = millis();
simpleChase();
}
}
void loop1() {
// Check if it's time to change the effect
if ((millis() - lastEffectChangeTime) > effectDuration) {
effect++;
if (effect > 4) { // Assuming 5 effects (0 to 4)
effect = 0;
}
lastEffectChangeTime = millis(); // Reset effect timer
}
// Execute the current effect
if ((millis() - changeTime) > ledDelay) {
changeTime = millis();
switch (effect) {
case 0:
simpleChase();
break;
case 1:
bounce();
break;
case 2:
twoWayChase();
break;
case 3:
blinkAll();
break;
case 4:
knightRider();
break;
}
}
}
void simpleChase() {
allLedsOff();
currentLED += direction;
if (currentLED == -1) {
direction = 1;
}
else if (currentLED == total_leds) {
direction = -1;
}
digitalWrite(leds[currentLED], HIGH);
}
void bounce() {
allLedsOff();
digitalWrite(leds[currentLED], HIGH);
currentLED += direction;
if (currentLED == total_leds || currentLED < 0) {
direction = -direction; // Reverse direction when hitting the ends
}
}
void twoWayChase() {
allLedsOff();
for (int i = 0; i < total_leds / 2; i++) {
digitalWrite(leds[i], HIGH);
digitalWrite(leds[total_leds - 1 - i], HIGH);
}
}
void blinkAll() {
static bool on = false;
allLedsOff();
if (on) {
for (int i = 0; i < total_leds; i++) {
digitalWrite(leds[i], HIGH);
}
}
on = !on;
}
void knightRider() {
allLedsOff();
digitalWrite(leds[currentLED], HIGH);
currentLED += direction;
if (currentLED == total_leds || currentLED == -1) {
direction = -direction;
}
}
void allLedsOff() {
for (int x = 0; x < total_leds; x++) {
digitalWrite(leds[x], LOW);
}
}