const int ledPins[8] = {13, 12, 14, 27, 26, 25, 33, 32};
const int potPin = 34;
unsigned long previousMillis = 0;
const long interval = 150;
int zone = 0;
int step = 0;
int direction = 1;
void turnOffAll() {
for (int i = 0; i < 8; i++) {
digitalWrite(ledPins[i], LOW);
}
}
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(potPin, INPUT);
}
void loop() {
int potValue = analogRead(potPin);
int newZone;
if (potValue <= 1365) {
newZone = 1;
} else if (potValue <= 2730) {
newZone = 2;
} else {
newZone = 3;
}
if (newZone != zone) {
zone = newZone;
step = 0;
direction = 1;
turnOffAll();
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
turnOffAll();
if (zone == 1) {
digitalWrite(ledPins[step], HIGH);
step++;
if (step >= 8) step = 0;
} else if (zone == 2) {
// --- Bounce / ping-pong ---
digitalWrite(ledPins[step], HIGH);
step += direction;
if (step >= 7) { step = 7; direction = -1; }
if (step <= 0) { step = 0; direction = 1; }
} else if (zone == 3) {
int left = 3 - step;
int right = 4 + step;
if (left >= 0) digitalWrite(ledPins[left], HIGH);
if (right <= 7) digitalWrite(ledPins[right], HIGH);
step++;
if (step > 3) step = 0;
}
}
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4