const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // LED pins for 10 LEDs
const int potPin = A0; // Potentiometer pin
int mode = 0; // Current mode
int potValue; // Value from potentiometer
void setup() {
for (int i = 0; i < 10; i++) { // Set up 10 LEDs
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
potValue = analogRead(potPin); // Read the potentiometer value
mode = map(potValue, 0, 1023, 0, 5); // Map to 6 modes (0-5)
switch (mode) {
case 0: // On (Stay)
for (int i = 0; i < 10; i++) { // Keep LEDs on
digitalWrite(ledPins[i], HIGH);
}
break;
case 1: // Chase Effect
for (int i = 0; i < 10; i++) {
digitalWrite(ledPins[i], HIGH); // Turn on the current LED
delay(200); // Wait for 200 milliseconds
digitalWrite(ledPins[i], LOW); // Turn off the current LED
}
break;
case 2: // Blink
for (int i = 0; i < 10; i++) {
digitalWrite(ledPins[i], HIGH);
}
delay(500);
for (int i = 0; i < 10; i++) {
digitalWrite(ledPins[i], LOW);
}
delay(500);
break;
case 3: // Close (Dim)
for (int i = 0; i < 10; i++) {
analogWrite(ledPins[i], 128); // Half brightness, only works with PWM pins
}
break;
case 4: // Sequential Blink
for (int i = 0; i < 10; i++) {
digitalWrite(ledPins[i], HIGH); // Turn on the current LED
delay(300); // Wait for 300 milliseconds
digitalWrite(ledPins[i], LOW); // Turn off the current LED
delay(50); // Wait before the next LED
}
break;
case 5: // Running Light Effect
// Forward direction
for (int i = 0; i < 10; i++) {
digitalWrite(ledPins[i], HIGH); // Turn on the current LED
delay(100); // Wait for 100 milliseconds
digitalWrite(ledPins[i], LOW); // Turn off the current LED
}
// Backward direction
for (int i = 8; i >= 0; i--) {
digitalWrite(ledPins[i], HIGH); // Turn on the current LED
delay(100); // Wait for 100 milliseconds
digitalWrite(ledPins[i], LOW); // Turn off the current LED
}
break;
}
}