const int potPin = A0; // Analog input pin for the potentiometer
const int ledCount = 10; // Number of LEDs in the bar graph
int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // Pins for the LEDs
void setup() {
// Initialize all LED pins as outputs
for (int i = 0; i < ledCount; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Read the potentiometer value (0-1023)
int sensorValue = analogRead(potPin);
// Map the sensor value to the number of LEDs to light (0-10)
int ledLevel = map(sensorValue, 0, 1023, 0, ledCount);
// Light up the LEDs up to the ledLevel
for (int i = 0; i < ledCount; i++) {
digitalWrite(ledPins[i], (i < ledLevel) ? HIGH : LOW);
}
// Small delay for stability
delay(10);
}