#include <Arduino.h>

// A0 wiper; D9 is PWM capable, with resistor and LED to GND.
const int potPin = A0;
// D9 supports PWM on the Uno, which lets us control perceived LED brightness.
const int ledPin = 9;

void setup() {
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // Read the potentiometer as a 10-bit number from 0 to 1023.
  int raw = analogRead(potPin);
  // map() scales the input range to 0–255 using integer math; it does not smooth noisy
  // readings.
  int brightness = map(raw, 0, 1023, 0, 255);
  // On the Uno, analogWrite controls PWM duty cycle here, not a smooth analog voltage.
  analogWrite(ledPin, brightness);
  // Print a label, the raw reading, then the PWM value so you can compare input and output.
  Serial.print("A0: ");
  Serial.print(raw);
  Serial.print(" PWM: ");
  Serial.println(brightness);
  // Repeat around every 50 ms to update the brightness and Serial display.
  delay(50);
}
