Test for 7 segment display

Hi All,
As a by product of a recent project I found this sketch for testing a 4x7 segment display (common cathode). The problem is that it does not light the decimal points of the display, I assumed that this was owing to line 18 reading “bool disableDecPoint = true;” so I changed the true to false but to no avail. I have tried various other edits, none of which have worked. I also wanted to reduce the brightness of the display so I changed the line Display.setBrightness(100) to various lower numbers but it made no noticeable difference. Can anyone point me in the right direction? Thanks.

// tests a 4x7 segment display by continually counting up using all 4 digits:  0000  1111   2222 etc.

#include "SevSeg.h"
SevSeg Display;

int number = 0;
//int ledState = LOW;
void setup()
{
 
  byte numDigits = 4;
  byte digitPins[] = {10, 11, 12, 13};
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
  bool resistorsOnSegments = false;
  bool updateWithDelays = false;
  byte hardwareConfig = COMMON_CATHODE;
  bool leadingZeros = true;
  bool disableDecPoint = true;
  Display.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  Display.setBrightness(100);
}
void loop()
{
  number = 0;
  for (int j = 0; j < 10; j++)
  {
    for (int i = 0; i < 3000; i++)
    {
      Display.setNumber(number);
      Display.refreshDisplay();
    }
    number = number + 1111;
  }
}

Where did you get the library from ?

You don't actually do anything in your code that would display a decimal point.

UK heliBob, can't remember where the library came from but it is the same library which I used for the previous project using the same 4x7 segment display and that worked fine, however that did not display decimal points either but I didn't need them in that instance.
aarg, What do I need to do in the code to display the decimal points?

Thanks both.

Sorry, the answer depends on which library you are using. Knowing that it is the same library that you used before doesn't help, because I don't know which library you used before... :slight_smile:

I will check tomorrow and let you know. Thanks.

Morning aarg, The library used was the one in the sketch on the project site, it is recommended for testing the 7 seg. displays: https://electronics-project-hub.com/arduino-7-segment-display-clock-with-and-without-rtc/. To be fair the decimal points did not operate on the display when I used the library in the that website project but it was not a problem for that use. However I would like to be able to test all segments of 7 segment displays, is there a library you would recommend trying? Thanks.

Morning all, I spent most of yesterday playing around with this sketch but it still refuses to light up the decimal points. I know the decimal points work as I have checked all the segments out using 5volts on each. I have also had them working using another sketch. It is just annoying me that I can't seem to sort out this programming problem. The library was downloaded from GitHub here: GitHub - DeanIsMe/SevSeg: Seven segment display controller library for Arduino, but I have also tried another library and that didn't work either. Any pointers would be greatly appreciated! Thanks.

Malc92:
Morning all, I spent most of yesterday playing around with this sketch but it still refuses to light up the decimal points. I know the decimal points work as I have checked all the segments out using 5volts on each. **I have also had them working using another sketch. **It is just annoying me that I can’t seem to sort out this programming problem. The library was downloaded from GitHub here: GitHub - DeanIsMe/SevSeg: Seven segment display controller library for Arduino, but I have also tried another library and that didn’t work either. Any pointers would be greatly appreciated! Thanks.

What was the other sketch?
What library did it use?
Can you post a copy of that sketch please?
Thanks… Tom… :slight_smile:

Hi Erik, thanks for your reply. I did read the section “setting a number” and when I applied the “second argument” to position the decimal point it did light it up in the position as described in the text. However my problem is that my sketch lights all 4 digits up at the same time, the counter is not counting 1,2,3,…etc. but 0000, 1111, 2222, 3333… etc. up to 9 then repeating. So, I need to tell the sketch that I need 4 decimal points, one after eash digit.

Hi Tom, thanks for your reply. The previous project was a simple clock using the large 7 segment display, it used the same library - from here GitHub - DeanIsMe/SevSeg: Seven segment display controller library for Arduino but to be fair it did not light the decimal point segments but that was not a problem for that application. Code is here. Thanks to both.

//mods to sketch nov06b. Clock with RTC displaying to 4x7 segment display (COM-11405). (Decimal points do not work.)

#include <SevSeg.h>
#include <DS3231.h>
DS3231  rtc(SDA, SCL);
Time  t;
SevSeg Display;
const int hrs_set = A0;
const int min_set = A1;
const int ledPin =  A3;
unsigned int number = 0;
unsigned long startMillis;
const long interval = 500;
unsigned long currentMillis;
unsigned long previousMillis = 0;
unsigned int Hour = 0;
unsigned int hrs_var = 0;
unsigned int min_var = 0;
int ledState = LOW;

void setup()
{
  rtc.begin();
  pinMode(ledPin, OUTPUT);
  pinMode(hrs_set, INPUT_PULLUP);
  pinMode(min_set, INPUT_PULLUP);
  byte numDigits = 4;
  byte digitPins[] = {10, 11, 12, 13};
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
  bool resistorsOnSegments = false;
  bool updateWithDelays = false;
  byte hardwareConfig = COMMON_CATHODE;
  bool leadingZeros = true;
  bool disableDecPoint = true;
  Display.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  Display.setBrightness(100);
}

void loop()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval)
  {
    previousMillis = currentMillis;
    if (ledState == LOW)
    {
      ledState = HIGH;
    }
    else
    {
      ledState = LOW;
    }
    digitalWrite(ledPin, ledState);
  }
  t = rtc.getTime();
  Hour = t.hour;
  hrs_var = t.hour;
  min_var = t.min;
  if (t.hour > 12)
  {
    if (t.hour == 13) Hour = 1;
    if (t.hour == 14) Hour = 2;
    if (t.hour == 15) Hour = 3;
    if (t.hour == 16) Hour = 4;
    if (t.hour == 17) Hour = 5;
    if (t.hour == 18) Hour = 6;
    if (t.hour == 19) Hour = 7;
    if (t.hour == 20) Hour = 8;
    if (t.hour == 21) Hour = 9;
    if (t.hour == 22) Hour = 10;
    if (t.hour == 23) Hour = 11;
  }
  else
  {
    if (t.hour == 0) Hour = 12;
  }
  number = Hour * 100 + t.min;
  Display.setNumber(number);
  Display.refreshDisplay();
  if (digitalRead(hrs_set) == LOW)
  {
    hrs_var += 1;
    if (hrs_var > 23) hrs_var = 0;  //this line changed, was previously:   if (hrs_var > 23) hrs_var == 0;   preventing the hrs set buton from working.
    rtc.setTime(hrs_var, min_var, 0);
    for (int i = 0; i < 1000; i ++)
    {
      Display.setNumber(number);
      Display.refreshDisplay();
    }
  }
  if (digitalRead(min_set) == LOW)
  {
    min_var += 1;
    if (min_var >= 60) min_var = 0;
    rtc.setTime(hrs_var, min_var, 0);
    for (int i = 0; i < 1000; i ++)
    {
      Display.setNumber(number);
      Display.refreshDisplay();
    }
  }
}

Your display refresh is buried in a for loop. The documentation that is linked to above, tells you to call it repeatedly,

Your program must run the refreshDisplay() function repeatedly to display the number. Note that any delays introduced by other functions will produce undesirable effects on the display.

So move it outside all your number calculations, so that it runs every time through the loop() function.

Hi aarg, I have moved the "refresh display" line out of the for loop as you suggest but it just splits up the 4 digit segments so they display individually i.e all the A segments, all the B segments, all the C segments etc. and still no sign of a decimal point.

You haven't posted your latest revision. By the way, what is it that you are actually trying to do?

The sketch supposed to test a 4x7segment display by displaying all the segments with a counter which should count 0000, 1.1.1.1. , 2.2.2.2. , 3.3.3.3. , etc. up to 9 and repeat. The revised code is below, I have tried moving the “refresh display” line to several different locations but to no avail. Thanks.

// tests a 4x7 segment display by continually counting up using all 4 digits:  0000  1111   2222 etc.


#include "SevSeg.h"
SevSeg sevseg;

int number = 0;
//int ledState = LOW;
void setup()
{
 
  byte numDigits = 4;
  byte digitPins[] = {10, 11, 12, 13};
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; 
  bool resistorsOnSegments = false;
  bool updateWithDelays = false;
  byte hardwareConfig = COMMON_CATHODE;
  bool leadingZeros = true;
  bool disableDecPoint = false;
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(100);
  

}
  
void loop()
 
{number = 0;
  for (int j = 0; j < 10; j++)
  {
    for (int i = 0; i < 3000; i++)
    {
     sevseg.setNumber(number);    
    
    }

    
   number = number + 1111;
  }
  sevseg.refreshDisplay(); 
}

Please describe exactly, the behaviour of the exact sketch that you just posted. "to no avail" is not a helpful description. We can't see the things you tried, so we have to focus only on what you post.

Also, what happens when you load a library example sketch?

When the sketch starts there is a delay of 5/6 secs with nothing happening. All the 4 B segments then light up for about 6 secs., then go out and all the 4 C segments do the same, then all the 4 D segments, then no segments light for 5/6 secs, then all the 4 F segments light up for 5/6 secs., and then all the 4 G segments, followed by all the A segments. The E segments do not light up at all and niether do the decimal point segments. In short, since moving the "refresh display" line the digits are not displaying 0000, 1111, 2222, etc. as they were previously.
I uploaded a couple of sketches from the example library as you suggested and they loaded and worked OK.

Ditch your program. Take an example program that works and change it, one small feature at a time, and test to make sure it still works before you move on.

That way, you will always know where the problem is.

It will be less painful than doing a post-mortem on code that was downloaded from a vanity site and then tinkered with randomly.

Hi aarg, Yes, I was beginning to think along those lines my self. The problem is that I don't really understand what I am doing with the code, and just seem to be getting deeper into trouble. None of the projects are important, they just help to keep my old brain functioning and then they annoy me when I try to get them going with my very limited coding ability. Still, I suppose it's a good way to learn - but slow and exasperating! I will take your advice and many thanks for your patience and help. Also, thanks to all others who tried to help. Malc.

Having started again with that sevseg test sketch. I have actually got it doing what it should. However the sketch is over 200 lines long and I can't help feeling there must be a better way of doing it. I would be grateful of suggestions from you fellows who know what you are doing!! Thanks in anticipation.

//  tests a 4x7 seg. disp. with modified blink sketch. displays 0000  1111  2222  3333 etc. with decimal points after all digits.

#define led  //output pins to 7 segment display
#define Don 1000  //delay setting the ON time of segments
#define Doff 250  //delay setting the OFF time of segments

void setup() {
  // put your setup code here, to run once:
pinMode(led 2, OUTPUT);   // A segment of display
pinMode(led 3, OUTPUT);   // B segment of display
pinMode(led 4, OUTPUT);   // C segment of display
pinMode(led 5, OUTPUT);   // D segment of display
pinMode(led 6, OUTPUT);   // E segment of display
pinMode(led 7, OUTPUT);   // F segment of display
pinMode(led 8, OUTPUT);   // G segment of display
pinMode(led 9, OUTPUT);   // Decimal Point segment of display
pinMode(led 10, OUTPUT);  // D1 cathode of display
pinMode(led 11, OUTPUT);  // D2 cathode of display
pinMode(led 12, OUTPUT);  // D3 cathode of display
pinMode(led 13, OUTPUT);  // D4 cathode of display
}
 
void loop()

{
   
  digitalWrite(2, HIGH);  // turn the following LEDs (segments) on to display the number 0. 
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(9, HIGH);
    
  delay(Don);   // wait for a second.
  
  digitalWrite(2, LOW);   //turn the following LEDs (segments)off.
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(9, LOW);
  
  //delay(Doff);  // wait for a second.

  digitalWrite(3, HIGH);   // turn the following LEDs (segnments)on to display the number 1.
  digitalWrite(4, HIGH);
  digitalWrite(9, HIGH);
 
  delay(Don);  // wait for a second
  
  digitalWrite(3, LOW);  //turn the following LEDs (segments)off. 
  digitalWrite(4, LOW);
  digitalWrite(9, LOW);     
  
 // delay(Doff);   // wait for a second

  digitalWrite(2, HIGH);   // turn the following LEDs (segnments)on to display the number 2.
  digitalWrite(3, HIGH);  
  digitalWrite(5, HIGH);  
  digitalWrite(6, HIGH);  
  digitalWrite(8, HIGH);  
  digitalWrite(9, HIGH);  
 
  delay(Don);    // wait for a second
  
  digitalWrite(2, LOW);   //turn the following LEDs (segments)off. 
  digitalWrite(3, LOW);  
  digitalWrite(5, LOW);  
  digitalWrite(6, LOW);  
  digitalWrite(8, LOW);  
  digitalWrite(9, LOW);
 
  //delay(Doff);   // wait for a second

  digitalWrite(2, HIGH);  // turn the following LEDs (segnments)on to display the number 3.
  digitalWrite(3, HIGH); 
  digitalWrite(4, HIGH); 
  digitalWrite(5, HIGH); 
  digitalWrite(8, HIGH); 
  digitalWrite(9, HIGH); 
 
  delay(Don);   // wait for a second
  
  digitalWrite(2,LOW);    //turn the following LEDs (segments)off.
  digitalWrite(3, LOW); 
  digitalWrite(4, LOW); 
  digitalWrite(5, LOW); 
  digitalWrite(8, LOW); 
  digitalWrite(9, LOW);
  
  //delay(Doff);   // wait for a second

  digitalWrite(3, HIGH);   // turn the following LEDs (segnments)on to display the number 4.
  digitalWrite(4, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
    
  delay(Don);  // wait for a second

  digitalWrite(3,LOW);    //turn the following LEDs (segments)off.
  digitalWrite(4, LOW); 
  digitalWrite(7, LOW); 
  digitalWrite(8, LOW); 
  digitalWrite(9, LOW); 
 
 // delay(Doff);  // wait for a second

  digitalWrite(2, HIGH);  // turn the following LEDs (segnments)on to display the number 5.
  digitalWrite(4, HIGH); 
  digitalWrite(5, HIGH); 
  digitalWrite(7, HIGH); 
  digitalWrite(8, HIGH); 
  digitalWrite(9, HIGH); 

  delay(Don);  // wait for a second

  digitalWrite(2,LOW);    //turn the following LEDs (segments)off.
  digitalWrite(4, LOW); 
  digitalWrite(5, LOW); 
  digitalWrite(7, LOW); 
  digitalWrite(8, LOW); 
  digitalWrite(9, LOW);

  //delay(Doff);  // wait for a second

  digitalWrite(2, HIGH);  // turn the following LEDs (segments) on to display the number 6. 
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);

  delay(Don);  // wait for a second

  digitalWrite(2, LOW);   //turn the following LEDs (segments)off.
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW); 

  //delay(Doff);  // wait for a second

  digitalWrite(2, HIGH);  // turn the following LEDs (segments) on to display the number 7. 
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(9, HIGH);

  delay(Don);  // wait for a second

  digitalWrite(2, LOW);   //turn the following LEDs (segments)off.
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(9, LOW);

  //delay(Doff);  // wait for a second

  digitalWrite(2, HIGH);  // turn the following LEDs (segments) on to display the number 8. 
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);

  delay(Don);  // wait for a second

  digitalWrite(2, LOW);   //turn the following LEDs (segments)off.
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);   
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);

  //delay(Doff);  // wait for a second

  digitalWrite(2, HIGH);  // turn the following LEDs (segments) on to display the number 9. 
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);           
  digitalWrite(5, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);

  delay(Don);  // wait for a second

  digitalWrite(2, LOW);   //turn the following LEDs (segments)off.
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(7, LOW);   
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);

  //delay(Doff);  // wait for a second
  
}