const int potPin = 9; // use a safe ADC pin
const int ledPin = 5;
const int pwmFreq = 5000;
const int pwmResolution = 8;
void setup() {
Serial.begin(115200);
ledcAttach(ledPin, pwmFreq, pwmResolution);
}
void loop() {
int potValue = analogRead(potPin);
int pwmValue = map(potValue, 0, 4095, 0, 255);
Serial.print("RAW=");
Serial.print(potValue);
Serial.print(" PWM=");
Serial.println(pwmValue);
ledcWrite(ledPin, pwmValue);
delay(10);
}