Skip to content

Instantly share code, notes, and snippets.

@FredDrago
Created June 17, 2014 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save FredDrago/7518eff4d55691565ce6 to your computer and use it in GitHub Desktop.
Save FredDrago/7518eff4d55691565ce6 to your computer and use it in GitHub Desktop.
Arduino demo for seven segment display by PetitStudio
#include <Adafruit_NeoPixel.h>
// Adapted from the Adafruit NeoPixel test example.
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_RGB Pixels are wired for RGB bitstream
// NEO_GRB Pixels are wired for GRB bitstream
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, 2, NEO_GRB + NEO_KHZ800);
const uint8_t numbers[10][8] {
{1,1,1,0,1,1,1,0}, // zero
{1,0,0,0,1,0,0,0}, // one
{0,1,1,1,1,1,0,0}, // two
{0,1,1,1,0,1,1,0}, // three
{1,0,1,1,0,0,1,0}, // four
{1,1,0,1,0,1,1,0}, // five
{1,1,0,1,1,1,1,0}, // six
{0,1,1,0,0,0,1,0}, // seven
{1,1,1,1,1,1,1,0}, // eight
{1,1,1,1,0,1,1,0}, // nine
};
uint32_t c[8] {
strip.Color(255,0,0),
strip.Color(0,255,0),
strip.Color(0,0,255),
strip.Color(255,255,0),
strip.Color(255,0,255),
strip.Color(0,255,255),
strip.Color(215,120,0),
strip.Color(255,255,255)
};
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// Some example procedures:
numbersWrite(strip.Color(255, 255, 255), numbers); // White
//numberColors(c, numbers);
//numbersRainbow(20,numbers);
//numbersRainbowCycle(10,numbers);
}
void numberColors(uint32_t c[8], const uint8_t num[][8]) {
for(uint8_t j=0; j<10; j++) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c[i] * num[j][i]);
strip.show();
}
delay(1000);
}
}
void numbersWrite(uint32_t c, const uint8_t num[][8]) {
for(uint8_t j=0; j<10; j++) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c * num[j][i]);
strip.show();
}
delay(1000);
}
}
void numbersRainbow(uint8_t wait,const uint8_t num[][8]) {
uint16_t i, j;
for (uint8_t k=0; k<10; k++) {
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, (Wheel((i+j) & 255)) * num[k][i]);
}
strip.show();
delay(wait);
}
}
}
// Slightly different, this makes the rainbow equally distributed throughout
void numbersRainbowCycle(uint8_t wait,const uint8_t num[][8]) {
uint16_t i, j;
for (uint8_t k=0; k<10; k++) {
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255) * num[k][i]);
//strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255) * num[8][i]);
}
strip.show();
delay(wait);
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment