const int potPin = 34;
const int ledPin = 4;
const int pwmFreq = 5000;
const int pwmResolution = 8;
void setup() {
Serial.begin(115200);
ledcAttach(ledPin, pwmFreq, pwmResolution);
}
void loop() {
int potValue = analogRead(potPin); // 0–4095
int pwmValue = map(potValue, 0, 4095, 0, 255); // scale to 8-bit
ledcWrite(ledPin, pwmValue);
Serial.print("Pot: ");
Serial.print(potValue);
Serial.print(" -> PWM: ");
Serial.println(pwmValue);
delay(50);
}Loading
esp32-devkit-c-v4
esp32-devkit-c-v4