I am making a 24 hour clock with a four digit seven segment display based on an arduino uno with the SevSeg.h library. Will recreate with a nano later on. Currently, the timer ticks up nicely from 0 to 23.59, but does not reset back to 0 like I want it to. It cuts back to around 21 something for a few cycles before defaulting back to 0 and no longer counting up.
Later, I will implement an actual way to set the clock so I can wear it and actually use it but for now, it's a counter problem.
Also, I am aware that I should use an external RTC if I want it to be accurate over longer periods of time, but this is just a proof of concept and I really do not care about longevity.
Here's the code so far, it's sped up considerably so I don't have to wait 24 hours for testing purposes:
#include "SevSeg.h"
SevSeg sevseg;
int startTime = 0;
int sec;
int minute;
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 updateWithDelaysIn = true;
byte hardwareConfig = COMMON_ANODE;
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
sevseg.setBrightness(100);
Serial.begin(9600);
}
void loop(){
sevseg.refreshDisplay();
long now = millis() - startTime;
now /= 50; //1000 for seconds, 50 for testing so I don't have to wait fucking forever
sec = now % 60;
minute = 100*(now / 60);
int displayNum = sec + minute;
if(displayNum > 2359){
startTime = millis();
now = millis();
displayNum = 0;
}
sevseg.setNumber(displayNum,2);
Serial.println(displayNum);
}
It is supposed to count from 0 to 2359 before reverting back to zero and counting up again. Just now while writing this I noticed that after about 5 minutes or so, it started counting up again after being stuck at 0 and later "--.--". Still not ideal ¯_(ツ)_/¯