const int ledPins[8] = {13, 12, 14, 27, 26, 25, 33, 32};
const int potPin = 34;
int currentLed = 0;
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(potPin, INPUT);
digitalWrite(ledPins[currentLed], HIGH);
}
void loop() {
int potValue = analogRead(potPin);
if (potValue >= 1900 && potValue <= 2200) {
return;
}
int delayTime;
int direction;
if (potValue < 1900) {
direction = -1;
delayTime = map(potValue, 0, 1899, 20, 400);
} else {
direction = 1;
delayTime = map(potValue, 2201, 4095, 400, 20);
}
for (int i = 0; i < 8; i++) {
digitalWrite(ledPins[i], LOW);
}
digitalWrite(ledPins[currentLed], HIGH);
delay(delayTime);
currentLed += direction;
if (currentLed >= 8) currentLed = 0;
if (currentLed < 0) currentLed = 7;
}
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4