#include <Arduino.h> // Explicitly include the standard Arduino library
// Define pins
static const int POT_PIN = A0; // Analog pin A0 for the potentiometer
static const int LED_PIN = 13; // Digital pin 13 (supports PWM) for LED control
void setup(void)
{
pinMode(LED_PIN, OUTPUT); // Set LED pin as an output
Serial.begin(9600); // Initialize serial communication at 9600 baud
}
void loop(void)
{
int potValue = analogRead(POT_PIN); // Read the potentiometer value (0-1023)
int ledBrightness = map(potValue, 0, 1023, 0, 255); // Scale value to 0-255 (PWM range)
analogWrite(LED_PIN, ledBrightness); // Set LED brightness using PWM
Serial.print("Potentiometer Value: "); // Print label to Serial Monitor
Serial.print(potValue); // Print raw potentiometer value
Serial.print(" | LED Brightness: "); // Print separator
Serial.println(ledBrightness); // Print mapped LED brightness value
delay(100); // Short delay (100ms) to stabilize readings
}