// Define pins for potentiometer and LED bar
const int potPin = A0; // Potentiometer connected to analog pin A0
const int ledBarPin = 13; // LED bar connected to digital pin 13
// Define variables
int potValue = 0; // variable to store potentiometer value
int brightness = 0; // variable to store LED bar brightness
void setup() {
// Set LED bar pin as output
pinMode(ledBarPin, OUTPUT);
// Begin serial communication for debugging
Serial.begin(9600);
}
void loop() {
// Read potentiometer value
potValue = analogRead(potPin);
// Map potentiometer value to LED bar brightness (0-255)
brightness = map(potValue, 0, 1023, 0, 255);
// Set LED bar brightness
analogWrite(ledBarPin, brightness);
// Debugging: print LED bar brightness
Serial.print("LED Bar Brightness: ");
Serial.println(brightness);
// Delay for stability
delay(100);
}