const int ledPin = 13; // the pin that the LED is attached to
const int potPin = A0; // the analog pin that the potentiometer is attached to
void setup() {
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output
}
void loop() {
int brightness = analogRead(potPin); // read the value from the potentiometer (0-1023)
brightness = map(brightness, 0, 1023, 0, 255); // map the potentiometer value to brightness range (0-255)
analogWrite(ledPin, brightness); // set the LED brightness using PWM
delay(10); // optional delay for smoother adjustment
}