int potPin = A0; // Analog pin for potentiometer
int ledPin = 9; // PWM pin connected to the LED
int potValue = 0; // Variable to store the potentiometer value
int ledBrightness = 0; // Variable to store LED brightness
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as output
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
potValue = analogRead(potPin); // Read the potentiometer value (0-1023)
ledBrightness = map(potValue, 0, 1023, 0, 255); // Map potentiometer value to PWM range (0-255)
analogWrite(ledPin, ledBrightness); // Set LED brightness using PWM
delay(10); // Small delay to avoid overwhelming the serial output
}