const int potPin = A0; // Analog pin connected to the potentiometer
const int ledPin = 9; // PWM pin connected to the LED
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
Serial.begin(9600); // Start serial communication at 9600 baud
}
void loop() {
int potValue = analogRead(potPin); // Read the analog value from the potentiometer
int ledBrightness = map(potValue, 0, 1023, 0, 255); // Map the potentiometer value to a range of 0-255
analogWrite(ledPin, ledBrightness); // Set the LED brightness
Serial.print("Potentiometer Value: ");
Serial.print(potValue);
Serial.print(" -> LED Brightness: ");
Serial.println(ledBrightness);
delay(100); // Wait for 100 milliseconds before taking another reading
}