2

I am attempting to make an Arduino counter using a 4 digit 7 segment display. The problem I am encountering is the display flickers. I am using an Arduino Uno and 5641AS digit display (so common cathode). Here is my program:

#include "SevSeg.h"
SevSeg sevseg;

int buttonPress{}; // Variable used in Serial monitor, simulates button press to increment counter void setup(){ byte numDigits = 4; byte digitPins[] = {10, 11, 12, 13}; byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4};

bool resistorsOnSegments = true;

bool updateWithDelays = false; byte hardwareConfig = COMMON_CATHODE; sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments); sevseg.setBrightness(90); Serial.begin(9600); sevseg.setNumber(0); sevseg.refreshDisplay(); } void loop(){ static int number = 0;

if (Serial.available() > 0) { // Serial monitor input for buttonPress buttonPress = Serial.read(); } Serial.println("The value of buttonPress is: "); Serial.println(buttonPress); if (buttonPress == 10){ // Increment counter if buttonPress Serial monitor input = 10 number += 15; buttonPress = 0; sevseg.setNumber(number); // Display the number on 4 digit 7 segment display
}

sevseg.refreshDisplay(); // Refresh display

}

I suspect this issue has to do with sevseg.refreshDisplay(), I have tried moving it in the program with no avail. My wiring is correct, as the program displays the correct digits. Thank you!

Sony
  • 110
  • 7

1 Answers1

2

With the help of Majenko and jsotola in the comments, I've got it fixed! It was the text I was displaying in the Serial Monitor that was slowing the display down. Here is the updated program that works:

#include "SevSeg.h"
SevSeg sevseg;

int buttonPress{}; // Variable used in Serial monitor, simulates button press to increment counter void setup(){ byte numDigits = 4; byte digitPins[] = {10, 11, 12, 13}; byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4};

bool resistorsOnSegments = true;

bool updateWithDelays = false; byte hardwareConfig = COMMON_CATHODE; sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments); sevseg.setBrightness(90); Serial.begin(9600); sevseg.setNumber(0); sevseg.refreshDisplay(); } void loop(){ static int number = 0;

if (Serial.available() > 0) { // Serial monitor input for buttonPress buttonPress = Serial.read(); } // THE NEXT TWO LINES HAVE BEEN COMMENTED OUT FOR IT TO WORK // Serial.println("The value of buttonPress is: "); // Serial.println(buttonPress); if (buttonPress == 10){ // Increment counter if buttonPress Serial monitor input = 10 number += 15; buttonPress = 0; sevseg.setNumber(number); // Display the number on 4 digit 7 segment display
}

sevseg.refreshDisplay(); // Refresh display

}

I'm leaving the program modifications here in case anyone else gets the same problem.

Sony
  • 110
  • 7