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
| Name | Description |
|---|---|
| A1–A10 | Anodes for segments 1–10 |
| C1–C10 | Cathodes for segments 1–10 |
Attributes
This component has no configurable attributes.
Usage
Connect each anode (A1–A10) through a 220 Ω current-limiting resistor to a GPIO pin, and each cathode (C1–C10) 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
| Description | Attrs |
|---|---|
| Default bar graph | {} |