I am using the sevseg library for a 7-segment 2-digit common cathode LED display, controlling it with an Arduino Mega.
For some reason, the "A" segment (top horizontal) of Digit 1 will not turn off during a countdown or count up. I switched the D1 and D2 lines and the problem moves to the other digit, so I know the segment works. It also turns off reliably with the sevseg.blank command.
The pins I am using are segments on 24, 25, 26, 27, 28, 29, 30, and the digit pins are 31 and 32.
I tried this with an Uno using pins 2,3, and 6,7,8,9,10,11,12. Countup works fine, but countdown has the problem with segment "A"
here is the code. I appreciate any thoughts!
#include "SevSeg.h"
SevSeg display;
bool gameTimed = true;
int timeleft = 90; // Total time is 90 seconds
unsigned long timer;
unsigned long currentTime;
byte numDigits = 2;
// byte digitPins[] = {31, 32};
// byte segmentPins[] = {24, 25, 26, 27, 28, 29, 30};
byte digitPins[] = {2, 3};
byte segmentPins[] = {6, 7, 8, 9, 10, 11, 12};
bool resistorsOnSegments = false; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_CATHODE; // See README.md for options
bool updateWithDelays = false; // Default. Recommended
bool leadingZeros = false; // Use 'true' if you'd like to keep the leading zeros
void setup() {
Serial.begin(115200);
display.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments, updateWithDelays, leadingZeros);
display.setBrightness(100);
// Timer
currentTime = millis();
display.setNumber(timeleft);
display.refreshDisplay();
Serial.print("\nEnd of setup");
}
void loop()
{
timeleft = 90; // Countdown timer from 90
currentTime = millis();
while (gameTimed) {
timer = millis();
if ((timer - currentTime) >= 200) // .2 sec per countdown
{ currentTime = millis();
timeleft--;
}
display.setNumber(timeleft);
display.refreshDisplay();
if (timeleft == 0)
gameTimed = false;
display.blank();
}
waitForSerial();
}
void waitForSerial() {
Serial.println("\nType any character then hit Enter to start timer...");
while (Serial.available() == 0) {}
Serial.read();
gameTimed = true;
}