My 7 segment 4 digit display is showing 6.6.6.6 and A.A.A

I am trying to make a reaction game like Formula 1. When each led lights up in its own time and then they all go dim. When they go dim I count the time and display it on the display. The problem I am facing is that the display shows 6.6.6 and A.A.A and sometimes has all the lights on. Is this a normal issue? If so how do I solve it? The code I am using is as follows:

#include <SevSeg.h>

void nextState(); // Forward declaration of function

SevSeg sevseg; // Instantiate a seven segment object
uint8_t state = 0;
uint8_t numDigits;
const uint32_t INTERVAL_MS = 500;

void setup() {
  // put your setup code here, to run once:
  pinMode(2, OUTPUT);
  pinMode(6, INPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  numDigits = 4;
  byte digitPins[] = {7, 8, 9, 10};
  byte segmentPins[] = {12, 13, 14, 15, 16, 17, 18, 19};
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_ANODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = false;
  bool stop = false;
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(90); // Set brightness if needed
  Serial.begin(9600); // Initialize serial communication


}

void loop() {

  
  int count = 1;
  bool stop = false;
  sevseg.blank();
  // put your main code here, to run repeatedly: 
  while (stop == false){
    count = count + 1;
    digitalWrite(count, HIGH);
    delay(1000);
    while (count == 5){
      int time = random(1000, 5000);
      delay(time);

      while (count > 1){
          digitalWrite(count, LOW);
          count = count - 1;

          
        }
      int counts = 0;
      while(digitalRead(6) == LOW){
        counts = counts + 1;
        delay(1);
      }
      float total = 0.000;
      total = (float)counts / 1000;
      int displayValue = total * 1000;
      Serial.println(total+0.075, 3 );
      int ds = round(total);
      sevseg.setNumber(ds); // Display the calculated value
      stop = true;
      delay(5000);
      sevseg.refreshDisplay();
      
      }
      }

    }

  
      




Your code uses delays that hinder the use of the SevSeg.h library.

See the text below and visit the library's author website.

" Warning: Any calls to delay() will interfere with the display. Any delays introduced by other functions will produce undesirable effects on the display. If you need help getting away from delay() statements, I recommend the simple Blink Without Delay arduino example sketch."

" GitHub - DeanIsMe/SevSeg: Seven segment display controller library for Arduino

Verify your hardware is common anode.

How do I find this? My display is 5641AS, it came with the start kit. I searched online and it said CATHODE but when I put it in the CATHODE the screen stopped working. The screen works in the tests that came with the sevseg file, just doesn't work with this one.

"Stopped working" - when? If you connect the 7seg display and all the LEDs start illuminating, that is "not working" and when no LEDs are illuminating, that is "working."

The LEDs should only light when the sketch commands them.

If your 7seg device has the word "CATHODE" on it, it is common cathode. To connect a common cathode 7seg, you connect the 7seg COM pin(s) to ground and the other 7seg pins to Arduino pins.

I didn't know that, thank you. The screen still doesn't display the values. What more should I change?

Again, if your 7seg is correctly connected, this is normal at the start. Only when the sketch sends signals to the 7seg should the LEDs illuminate.

Verify your wiring is correct. Describe what you see on the Arduino, on the IDE and on the 7seg.

@milima
I suggest you run, (using your project's pins), the example
SevSeg_Counter.ino from the SevSeg.h library.
This way you will see if your Hardware is correct.

"SevSeg/examples/SevSeg_Counter/SevSeg_Counter.ino at master · DeanIsMe/SevSeg · GitHub

The hardware is ok as I tested it, just the software is not working as it should be.
On the 7seg I see nothing, in the arduino the LEDs work as they should. The only thing that is not working is the screen.

The software is working exactly as it is being instructed. Use the Serial Monitor to show the present output to help resolve the hardware and software issue.

Hi @milima ,

Weclome to the forum..

really??

No, not sure if you need a programmer or a priest..

That's the demon called delay that you were told about in post #3..

I like games..

Mega Game React

all those whiles in whiles, pretty confusing, hopefully i've unrolled them proper..

/*
https://forum.arduino.cc/t/my-7-segment-4-digit-display-is-showing-6-6-6-6-and-a-a-a/1263953

*/



#include <SevSeg.h>


SevSeg sevseg; // Instantiate a seven segment object
uint8_t state = 0;
uint8_t numDigits;
const uint32_t INTERVAL_MS = 500;

byte stateSys = 0;
unsigned long lastStep;
unsigned long intervalStep = 1000;
int count = 1;
int counts = 0;
float total = 0.000;
int ds = 0;


void setup() {
  // put your setup code here, to run once:
  pinMode(2, OUTPUT);
  pinMode(6, INPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  numDigits = 4;
  byte digitPins[] = {7, 8, 9, 10};
  byte segmentPins[] = {12, 13, 14, 15, 16, 17, 18, 19};
  bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
  byte hardwareConfig = COMMON_ANODE; // See README.md for options
  bool updateWithDelays = false; // Default 'false' is Recommended
  bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
  bool disableDecPoint = false;
  bool stop = false;
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros, disableDecPoint);
  sevseg.setBrightness(90); // Set brightness if needed
  Serial.begin(9600); // Initialize serial communication

}



void loop() {

  
unsigned long now  = millis();
//pump that screen..
sevseg.refreshDisplay();

 if (now - lastStep >= intervalStep){
    switch (stateSys){

       case 0: count = 1;
               sevseg.blank();
               stateSys++;  
               break; 
       case 1: if (count < 5){
               count++;
               digitalWrite(count, HIGH);
               lastStep = now;
               intervalStep = 1000;
                } else {
                  stateSys++;
                  lastStep = now;
                   randomSeed(analogRead(0));
                  intervalStep = random(1000,5000);
                }
               break;
       case 2: if (count > 1){
                   digitalWrite(count, LOW);
                   count--;
                  } else{
                     stateSys++;
                     counts = 0;
                  }
               break;
      case 3: if (digitalRead(6)== LOW){
                  counts++;
                  lastStep = now;
                  intervalStep = 1; //??? that's fast
                 } else stateSys++;
                break;
      case 4:  total = (float)counts / 1000;
               Serial.println(total+0.075, 3 );//why the math??
               ds = round(total);
               sevseg.setNumber(ds); // Display the calculated value 
               stateSys++;
               lastStep = now;
               intervalStep = 5000;
               break;
       case 5: stateSys = 0;
               break;                  
   } //end switch
 } //end time for a step
  
}

good luck.. ~q

I am speechless! You are a life saviour. You just saved me hours and hours of pain and headaches. After a few adjustments to the code, it worked perfectly. I can't thank you enough :slight_smile:

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.