// https://www.youtube.com/watch?v=cBO9Cn52fJY
//const int numLEDs = 8;
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17};
// https://www.arduino.cc/reference/en/language/variables/utilities/sizeof/
// sizeof(); https://forum.arduino.cc/t/how-do-you-check-the-length-of-an-array/88325/7
int numLEDs = sizeof(ledPins)/sizeof(int);
void setup() {
for (int i = 0; i < numLEDs; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop1() {
pattern30();
//pattern4();
}
void loop() {
pattern1();
delay(500);
pattern2();
delay(500);
pattern3();
delay(500);
pattern4();
delay(500);
pattern5();
delay(500);
pattern6();
delay(500);
pattern7();
delay(500);
pattern8();
delay(500);
pattern9();
delay(500);
pattern10();
delay(500);
pattern11();
delay(500);
pattern12();
delay(500);
pattern13();
delay(500);
pattern14();
delay(500);
pattern15();
delay(500);
pattern16();
delay(500);
pattern17();
delay(500);
pattern18();
delay(500);
pattern19();
delay(500);
pattern20();
delay(500);
pattern21();
delay(500);
pattern22();
delay(500);
pattern23();
delay(500);
pattern24();
delay(500);
pattern25();
delay(500);
pattern26();
delay(500);
pattern27();
delay(500);
pattern28();
delay(500);
pattern29();
delay(500);
pattern30();
delay(500);
}
void pattern1() {
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(100);
digitalWrite(ledPins[i], LOW);
}
}
void pattern2() {
for (int i = numLEDs - 1; i >= 0; i--) {
digitalWrite(ledPins[i], HIGH);
delay(100);
digitalWrite(ledPins[i], LOW);
}
}
void pattern3() {
for (int i = 0; i < numLEDs; i += 2) {
digitalWrite(ledPins[i], HIGH);
}
delay(300);
for (int i = 0; i < numLEDs; i += 2) {
digitalWrite(ledPins[i], LOW);
}
delay(200);
}
void pattern4() {
for (int i = 1; i < numLEDs; i += 2) {
digitalWrite(ledPins[i], HIGH);
}
delay(300);
for (int i = 1; i < numLEDs; i += 2) {
digitalWrite(ledPins[i], LOW);
}
delay(200);
}
void pattern5() {
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
}
delay(500);
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(200);
}
void pattern6() {
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(50);
}
delay(100);
for (int i = numLEDs - 1; i >= 0; i--) {
digitalWrite(ledPins[i], LOW);
delay(50);
}
delay(100);
}
void pattern7() {
for (int j = 0; j < 3; j++) {
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(50);
digitalWrite(ledPins[i], LOW);
}
}
}
void pattern8() {
for (int j = 0; j < 3; j++) {
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], (i % 2 == 0) ? HIGH : LOW);
}
delay(500);
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(500);
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], (i % 2 == 1) ? HIGH : LOW);
}
delay(500);
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(500);
}
}
void pattern9() {
// Heartbeat effect
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
}
delay(300);
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(300);
}
void pattern10() {
// Theater chase effect
for (int j = 0; j < 3; j++) {
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(100);
digitalWrite(ledPins[i], LOW);
}
}
}
void pattern11() {
// Random blink
for (int i = 0; i < 10; i++) {
int led = random(0, numLEDs);
digitalWrite(ledPins[led], HIGH);
delay(100);
digitalWrite(ledPins[led], LOW);
delay(100);
}
}
void pattern12() {
// All LEDs blink together
for (int i = 0; i < 3; i++) {
for (int j = 0; j < numLEDs; j++) {
digitalWrite(ledPins[j], HIGH);
}
delay(500);
for (int j = 0; j < numLEDs; j++) {
digitalWrite(ledPins[j], LOW);
}
delay(500);
}
}
void pattern13() {
// Running light with fade effect
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(200);
}
for (int i = numLEDs - 1; i >= 0; i--) {
digitalWrite(ledPins[i], LOW);
delay(200);
}
}
void pattern14() {
// Alternate blink
for (int i = 0; i < numLEDs; i += 2) {
digitalWrite(ledPins[i], HIGH);
}
delay(500);
for (int i = 0; i < numLEDs; i += 2) {
digitalWrite(ledPins[i], LOW);
}
}
void pattern15() {
// Inverted running light
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
delay(200);
}
for (int i = numLEDs - 1; i >= 0; i--) {
digitalWrite(ledPins[i], HIGH);
delay(200);
}
}
void pattern16() {
// Pulse effect
for (int brightness = 0; brightness <= 255; brightness += 5) {
for (int i = 0; i < numLEDs; i++) {
analogWrite(ledPins[i], brightness);
}
delay(30);
}
for (int brightness = 255; brightness >= 0; brightness -= 5) {
for (int i = 0; i < numLEDs; i++) {
analogWrite(ledPins[i], brightness);
}
delay(30);
}
}
void pattern17() {
// Left/right alternation
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], HIGH);
digitalWrite(ledPins[i + 4], LOW);
delay(300);
}
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], LOW);
digitalWrite(ledPins[i + 4], HIGH);
delay(300);
}
}
void pattern18() {
// Wave pattern
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(100);
digitalWrite(ledPins[i], LOW);
}
for (int i = numLEDs - 1; i >= 0; i--) {
digitalWrite(ledPins[i], HIGH);
delay(100);
digitalWrite(ledPins[i], LOW);
}
}
void pattern19() {
// Random wave
for (int i = 0; i < 10; i++) {
int led = random(0, numLEDs);
digitalWrite(ledPins[led], HIGH);
delay(100);
digitalWrite(ledPins[led], LOW);
}
}
void pattern20() {
// Snake pattern
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(200);
digitalWrite(ledPins[i], LOW);
}
for (int i = numLEDs - 1; i >= 0; i--) {
digitalWrite(ledPins[i], HIGH);
delay(200);
digitalWrite(ledPins[i], LOW);
}
}
void pattern21() {
// Inverted blink
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(500);
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
}
delay(500);
}
void pattern22() {
// All on, all off
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
}
delay(1000);
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(1000);
}
void pattern23() {
// Mirror effect
for (int i = 0; i < numLEDs / 2; i++) {
digitalWrite(ledPins[i], HIGH);
digitalWrite(ledPins[numLEDs - 1 - i], HIGH);
delay(100);
digitalWrite(ledPins[i], LOW);
digitalWrite(ledPins[numLEDs - 1 - i], LOW);
}
}
void pattern24() {
// Dual running lights
for (int i = 0; i < numLEDs / 2; i++) {
digitalWrite(ledPins[i], HIGH);
digitalWrite(ledPins[numLEDs - 1 - i], HIGH);
delay(200);
digitalWrite(ledPins[i], LOW);
digitalWrite(ledPins[numLEDs - 1 - i], LOW);
}
}
void pattern25() {
// Chase with pause
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(100);
}
delay(500);
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
}
void pattern26() {
// Rainbow effect (for RGB LEDs)
for (int j = 0; j < 3; j++) {
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(100);
digitalWrite(ledPins[i], LOW);
}
}
}
void pattern27() {
// Random flicker
for (int i = 0; i < 10; i++) {
int led = random(0, numLEDs);
digitalWrite(ledPins[led], HIGH);
delay(random(100, 500));
digitalWrite(ledPins[led], LOW);
delay(random(100, 500));
}
}
void pattern28() {
// Breathing light
for (int brightness = 0; brightness <= 255; brightness += 5) {
for (int i = 0; i < numLEDs; i++) {
analogWrite(ledPins[i], brightness);
}
delay(30);
}
for (int brightness = 255; brightness >= 0; brightness -= 5) {
for (int i = 0; i < numLEDs; i++) {
analogWrite(ledPins[i], brightness);
}
delay(30);
}
}
void pattern29() {
// Direction change blink
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
}
delay(500);
for (int i = numLEDs - 1; i >= 0; i--) {
digitalWrite(ledPins[i], LOW);
}
delay(500);
}
void pattern30() {
// All LEDs in sequence
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], HIGH);
delay(200);
}
for (int i = 0; i < numLEDs; i++) {
digitalWrite(ledPins[i], LOW);
}
}