I thought of the idea of using the WS2312B LED strip to drive a custom 7-Segment display. The project will require a large number of these displays, and driving them with a single Arduino (I'm thinking of an Arduino MEGA). For driving the LEDs I am using the FastLED library.
I wrote some code that drives a single display, It works, but I think It's possible to make it simpler, the code I wrote stores the digits in arrays, and uses these arrays in functions customized to each digit. here is an example:
//Digit Arrays:
byte digit0[] = {0,1,2,3,4,5};
byte digit1[] = {1,2};
byte digit2[] = {0,1,3,4,6};
byte digit3[] = {0,1,2,3,6};
byte digit4[] = {1,2,5,6};
byte digit5[] = {0,2,3,5,6};
byte digit6[] = {0,2,3,4,5,6};
byte digit7[] = {0,1,2};
byte digit8[] = {0,1,2,3,4,5,6};
byte digit9[] = {0,1,2,3,5,6};
The functions are something like this:
void AllOff(){
//Switch off All the LEDs in the segment. Should be off for 1 second
for(int i=0; i<7; i++){
leds[i] = CRGB::Black;
FastLED.show();
}
//delay(1000);
}
void AllOn(CRGB myColor){
//Switch on All the LEDs in the segment (should display 8)
//The color of choice is #1E78A0
for(int i=0; i<7; i++){
leds[i] = CRGB (30,120,160);
FastLED.show();
}
delay(1000);
}
void Print0(CRGB myColor){
//Prints the digit 0:
AllOff();
ArraySize = sizeof(digit0); //get the size of the array
for(int i=0; i<ArraySize; i++){
LED_Number = digit0[i]; //get the LED number from the array
leds[LED_Number] = CRGB (myColor); //Switch the LED on
FastLED.show();
}
}
When I call it in the code, I simply do something like this:
Print0(CRGB::Purple);
delay(500);
I have tried for the best part of the past two days to find a better way to go about this, but I couldn't. What I'm thinking is perhaps to create a function that would store all the digits instead of storing every one as an array, and then call it maybe within a for loop? something like
for(int i=0; i<10; i++){
displaydigit[i];
FastLED.show();
}
Do you know of any library that has something similar, or perhaps any idea on how to achieve this?
Your assistance, as always, is greatly appreciated.
Thank You.