Hello,
I'm pretty new to Arduino, but I'm familiar to programming. I'm currently making a scoreboard and i'm using 6 7-segment displays.
I use some WS2812B addressable LEDs and an Arduino Nano. I use the NeoPixel library.
Each display contains 21 addressable LEDs and each display is also controlled by one outputs.
Each segment of a 7-segment display can be illuminated by a group of 3 addressable LEDs (see the attachments for more details. Arrows and numbers show the direction and order of the LEDs).
Here's how the elements are connected (just to give you an idea, it's very simplified) :
As I use multiple 6 7-segment display, the code is the same for each display, except for the output where the addressable LEDs are connected. I didn't want to write the code 6 times, so I tried to do a function I could call 6 times.
For a test, I tried to use only 2 7-segment display, so I can count from 0 to 99. I made a "main programm" and I create my function in a second tab.
Here is the code in the first tab (the "main" code) :
#include <Adafruit_NeoPixel.h>
#define LED_PIN_unit 2
#define LED_PIN_ten 4
#define LED_COUNT 28
#define RED 255
#define GREEN 0
#define BLUE 0
#define WHITE 0
#define Brightness 255
Adafruit_NeoPixel unit_display(LED_COUNT, LED_PIN_unit, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel ten_display(LED_COUNT, LED_PIN_ten, NEO_GRBW + NEO_KHZ800);
int segment1 [] = {0, 1, 2, 3};
int segment2 [] = {4, 5, 6, 7};
int segment3 [] = {8, 9, 11, 10};
int segment4 [] = {12, 13, 14, 15};
int segment5 [] = {16, 17, 18, 19};
int segment6 [] = {20, 21, 22, 23};
int segment7 [] = {24, 25, 26, 27};
int count = 0;
int count_unit = 0;
int count_ten = 0;
uint32_t color_unit = unit_display.Color(RED, GREEN, BLUE, WHITE); // Couleur des chiffres des unités
uint32_t off_unit = unit_display.Color(0, 0, 0);
uint32_t color_ten = ten_display.Color(RED, GREEN, BLUE, WHITE); // Couleur des chiffres des dizaines
uint32_t off_ten = ten_display.Color(0, 0, 0);
void setup() {
Serial.begin(9600);
unit_display.begin();
ten_display.begin();
unit_display.setBrightness(Brightness);
ten_display.setBrightness(Brightness);
unit_display.clear();
ten_display.clear();
unit_display.show();
ten_display.show();
}
void loop() {
Display(unit_display, count_unit, color_unit);
Display(ten_display, count_ten, color_ten);
count++;
count_unit++;
if (count_unit >= 10) {
count_unit = 0;
count_ten++;
}
if (count_ten >= 10) {
count_ten = 0;
}
Serial.println(count_unit);
delay(1000);
}
And here is my function (in the second tab) :
void Display(Adafruit_NeoPixel strip_name, int count_value, uint32_t color_on) {
//Segment 1 -- (right up) ----------------------------------------------------------------------------------------------
if (count_value == 0 || count_value == 1 || count_value == 2 || count_value == 3 || count_value == 4 || count_value == 7 || count_value == 8 || count_value == 9) {
strip_name.fill(color_on, 0, 3);
}
else {
strip_name.fill(strip_name.Color(0, 0, 0, 0), 0, 3);
}
//Segment 2 -- (up) ----------------------------------------------------------------------------------------------------
if (count_value == 0 || count_value == 2 || count_value == 3 || count_value == 5 || count_value == 6 || count_value == 7 || count_value == 8 || count_value == 9) {
strip_name.fill(color_on, 3, 3);
}
else {
strip_name.fill(strip_name.Color(0, 0, 0, 0), 3, 3);
}
//Segment 3 -- (left up) ---------------------------------------------------------------------------------------------
if (count_value == 0 || count_value == 4 || count_value == 5 || count_value == 6 || count_value == 8 || count_value == 9) {
strip_name.fill(color_on, 6, 3);
}
else {
strip_name.fill(strip_name.Color(0, 0, 0, 0), 6, 3);
}
//Segment 4 -- (left down) ----------------------------------------------------------------------------------------------
if (count_value == 0 || count_value == 2 || count_value == 6 || count_value == 8 || count_value == 10) {
strip_name.fill(color_on, 9, 3);
}
else {
strip_name.fill(strip_name.Color(0, 0, 0, 0), 9, 3);
}
//Segment 5 -- (down) -----------------------------------------------------------------------------------------------------
if (count_value == 0 || count_value == 2 || count_value == 3 || count_value == 5 || count_value == 6 || count_value == 8 || count_value == 9) {
strip_name.fill(color_on, 12, 3);
}
else {
strip_name.fill(strip_name.Color(0, 0, 0, 0), 12, 3);
}
//Segment 6 -- (right down) -----------------------------------------------------------------------------------------------
if (count_value == 0 || count_value == 1 || count_value == 3 || count_value == 4 || count_value == 5 || count_value == 6 || count_value == 7 || count_value == 8 || count_value == 9) {
strip_name.fill(color_on, 15, 3);
}
else {
strip_name.fill(strip_name.Color(0, 0, 0, 0), 15, 3);
}
//Segment 7 -- (middle) --------------------------------------------------------------------------------------------------
if (count_value == 2 || count_value == 3 || count_value == 4 || count_value == 5 || count_value == 6 || count_value == 8 || count_value == 9) {
strip_name.fill(color_on, 18, 3);
}
else {
strip_name.fill(strip_name.Color(0, 0, 0, 0), 18, 3);
}
strip_name.show();
}
I tried that but the problem is that the function in the main programm is only executed one time. In my case, my display stays stuck on "00" when it should go to "01", then "02", etc.
So I tried to make a smaller and simplier programm, but I also used a "main" programme and a function in a new tab.
Here is the "main" programm:
#include <Adafruit_NeoPixel.h>
#define LED_PIN 4
#define LED_COUNT 28
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
void setup() {
Serial.begin(9600);
strip.begin();
strip.clear();
strip.show();
}
void loop() {
Display(strip, 0);
Serial.println("Again");
delay(1000);
}
And here is the function :
void Display(Adafruit_NeoPixel strip_name, int LED_NUMBER) {
strip_name.setPixelColor(LED_NUMBER, 255, 0, 0, 0);
Serial.println("ON");
strip_name.show();
delay(1000);
strip_name.clear();
Serial.println("OFF");
strip_name.show();
delay(1000);
}
And after I tried that, I saw that the function was only running once again.
I really don't understand why my function is only running one time. I tried a lot of things to fix this problem, but nothing works.
Can anyone help me ?

