const int ledPin = 9; // The PWM pin connected to the LED
const int potPin = A0; // The analog pin connected to the potentiometer
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
Serial.begin(9600); // Start serial communication for debugging
}
void loop() {
// Read the potentiometer value (0-1023)
int potValue = analogRead(potPin);
// Map the potentiometer's 10-bit value to the LED's 8-bit brightness (0-255)
int brightness = map(potValue, 0, 1023, 0, 255);
// Write the brightness value to the LED
analogWrite(ledPin, brightness);
Serial.print("Pot Value: ");
Serial.print(potValue);
Serial.print(" | Brightness: ");
Serial.println(brightness);
delay(10); // Small delay for stability
}