#include <Arduino.h>

// A0 potentiometer; D8-D12 each needs separate resistor/LED to GND.
const int potPin = A0;
// These five outputs make an LED bar graph. Each LED has its own current-limiting resistor.
const int ledPins[] = {8, 9, 10, 11, 12};

void setup() {
  Serial.begin(9600);
  // Configure all five pins as outputs using one loop.
  for (int i = 0; i < 5; i++) pinMode(ledPins[i], OUTPUT);
}

void loop() {
  // Read the potentiometer voltage on A0 as a number from 0 to 1023.
  int raw = analogRead(potPin);
  // Convert the analog reading into a count of LEDs to light, from 0 to 5.
  int lit = map(raw, 0, 1023, 0, 5);
  Serial.println(raw);
  // Visit each LED position. i starts at 0, increases by 1, and stops before 5.
  for (int i = 0; i < 5; i++) {
    // The first lit LEDs turn on; the rest turn off. This creates the bar display.
    digitalWrite(ledPins[i], i < lit ? HIGH : LOW);
  }
  delay(50);
}
