const int potPin = A0; // Potentiometer input
const int ledPin = 9; // PWM output pin
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int potValue = analogRead(potPin); // Range: 0–1023
int brightness = map(potValue, 0, 1023, 0, 255); // Scale to PWM range
analogWrite(ledPin, brightness); // Set LED brightness
delay(10); // Smooth update
}