I used sevseg.h library to write numbers to my 4 digit seven segment. The display should update every second with the current time since program started running. This is my code so far:
#include <SevSeg.h>
SevSeg sevseg;
void setup() {
byte numDigits = 4;
byte digitPins[] = {5, 4, 3, 2};
byte segmentPins[] = {13, 12, 11, 10, 9, 8, 7, 6};
sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
sevseg.setBrightness(50);
sevseg.setNumber(0000, -1);
}
void loop() {
unsigned long timer = millis();
for (int i = 0; i < 500; i++) {
sevseg.setNumber(timer/1000, -1);
sevseg.refreshDisplay();
delay(2);
}
}
Since the delay is 2, the for loop loops 500 times, resulting in 1000ms or 1 second. The current second is written to the display. For some reason, the display is updated every other 5 or 6 seconds. Why is this occurring? How can this be fixed so that my display turns into a stopwatch in a way?