// Common (-) LED pins
const byte ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
const byte ledCount = sizeof ledPins / sizeof ledPins[0];
// RGB + pins
const byte RED_PIN = 12;
const byte GREEN_PIN = 13;
const byte BLUE_PIN = A0;
// Pot Pins
const byte LED_SPEED_POT = A4; // LED Steping speed
const byte RGB_SPEED_POT = A2; // RGB Color Speed
void setup() {
for (byte i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
digitalWrite(ledPins[i], LOW);
}
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop() {
static byte ledIndex = 0;
static byte colorIndex = 0;
uint32_t now = millis();
static uint32_t ledMillis = 0;
static uint32_t rgbMillis = 0;
// --- Pots Readings ---
uint32_t ledInterval = map(analogRead(LED_SPEED_POT), 0, 1023, 50, 1000);
uint32_t rgbInterval = map(analogRead(RGB_SPEED_POT), 0, 1023, 50, 1000);
// ---------- LED Interval ----------
if (now - ledMillis >= ledInterval) {
ledMillis = now;
// All LEDs Off
for (byte i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], LOW);
}
// Next LED
digitalWrite(ledPins[ledIndex], HIGH);
ledIndex++;
if (ledIndex >= ledCount) ledIndex = 0;
}
// ---------- RGB Color Gradient ----------
if (now - rgbMillis >= rgbInterval) {
rgbMillis = now;
colorIndex++;
if (colorIndex > 0b0111) colorIndex = 1;
digitalWrite(RED_PIN, !(colorIndex & 1));
digitalWrite(GREEN_PIN, !(colorIndex & 2));
digitalWrite(BLUE_PIN, !(colorIndex & 4));
}
}