const int ledPin = 9; // LED connected to digital pin 9
const int potPin = A0; // Potentiometer connected to analog pin A0
int potValue = 0; // Variable to store the potentiometer value
int ledBrightness = 0; // Variable to store the LED brightness
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as an output
pinMode(potPin, INPUT); // Set the potentiometer pin as an input
}
void loop() {
potValue = analogRead(potPin); // Read the potentiometer value (0-1023)
ledBrightness = map(potValue, 0, 1023, 0, 255); // Map the value to a range of 0-255
analogWrite(ledPin, ledBrightness); // Set the LED brightness
delay(10); // Small delay for stability
}