Skip to content

Instantly share code, notes, and snippets.

@rubyist
Last active January 3, 2016 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubyist/8513692 to your computer and use it in GitHub Desktop.
Save rubyist/8513692 to your computer and use it in GitHub Desktop.
LED strip as seven segment display, 3 LEDs per segment.
#include <Adafruit_NeoPixel.h>
#define PIN 8
Adafruit_NeoPixel strip = Adafruit_NeoPixel(24, PIN, NEO_GRB + NEO_KHZ800);
// LED strip, 3 LEDs per segment, standard 7 segment LED layout
unsigned long DigitBytes[] = {
0x0003FFFF, // 0
0x000001F8, // 1
0x001C7E3F, // 2
0x001C0FFF, // 3
0x001F81F8, // 4
0x001F8FC7, // 5
0x001FFFC7, // 6
0x000001FF, // 7
0x001FFFFF, // 8
0x001F81FF // 9
};
void setup() {
strip.begin();
strip.show();
}
void showDigit(int d) {
unsigned long digit = DigitBytes[d];
for (int i = 0; i < 21; i++) {
if (digit & 1) {
strip.setPixelColor(i, 0xFF0000);
} else {
strip.setPixelColor(i, 0x000000);
}
digit = digit >> 1;
}
strip.show();
}
void loop() {
for (int x = 0; x < 10; x++) {
showDigit(x);
delay(5000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment