const int potPin = 6; // VR ต่อที่ขา ADC เช่น GPIO32
const int ledPin[] = {15, 23, 21, 18, 9}; // LED ต่อขา PWM เช่น GPIO14, 27 ฯลฯ
void setup() {
for(int i=0; i<5; i++) {
pinMode(ledPin[i], OUTPUT);
}
Serial.begin(115200);
}
void loop() {
int potValue = analogRead(potPin); // อ่านค่า VR (0-4095)
int level = map(potValue, 0, 4095, 0, 5); // แปลงช่วงค่า (ESP32 ให้ค่า 0–4095)
for(int i=0;i<5;i++){
digitalWrite(ledPin[i], (i < level) ? HIGH : LOW); // ให้ LED ติดตามช่วงค่า
}
delay(50);
}
Loading
esp32-c6-devkitc-1
esp32-c6-devkitc-1