CNAP

LED Bar Graph Reference

A 10-segment bar of individually addressable LEDs in a single package, each with its own anode and cathode.

Pin names

NameDescription
A1–A10Anodes for segments 1–10
C1–C10Cathodes for segments 1–10

Attributes

This component has no configurable attributes.

Usage

Connect each anode (A1A10) through a 220 Ω current-limiting resistor to a GPIO pin, and each cathode (C1C10) to GND. Drive a segment's GPIO HIGH to light it.

const int NUM_LEDS = 10;
const int PINS[NUM_LEDS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};

void setup() {
  for (int i = 0; i < NUM_LEDS; i++) {
    pinMode(PINS[i], OUTPUT);
  }
}

void loop() {
  // Sweep forward
  for (int i = 0; i < NUM_LEDS; i++) {
    digitalWrite(PINS[i], HIGH);
    delay(60);
    digitalWrite(PINS[i], LOW);
  }
  // Sweep backward
  for (int i = NUM_LEDS - 2; i > 0; i--) {
    digitalWrite(PINS[i], HIGH);
    delay(60);
    digitalWrite(PINS[i], LOW);
  }
}

Examples

DescriptionAttrs
Default bar graph{}

See also

  • Resistor — one per anode pin, 220 Ω typical
  • LED — each segment is functionally a single LED
  • LED Ring — addressable LEDs arranged in a ring instead of a bar