Okay, so, my code is getting pretty long for the project I'm working on, and I'm almost positive that is the culprit for this particular issue, but I'm not sure how to resolve it! Long story short, I'm building a clock, and I want the seconds to count in the corner, while the time is listed in the center. The problem I'm having is that the seconds will not increment in consistent intervals. By that I mean that the seconds displayed don't change every second, they sometimes change even after just a fraction of a second. I'm having difficulty making this easy. I was thinking of using an interrupt to force it to increment in time with the RTC I'm using, but I'm not really comfortable with interrupts yet, and I don't want the clock to interfere with other functions. On to the code!
//RTC Variables
int rtcyear;
int rtcmonth;
int rtcday;
int rtchour;
int rtcmin;
int rtcsec;
//Subroutine to display clock values on clockscreen
void rtcClockScreenDisplay()
{
DateTime now = rtc.now();
boolean timeChange = true;
boolean secondChange = true;
int clockScreenHour;
int clockScreenMinute;
if (timeChange)
{
clockScreenHour = now.hour();
if (clockScreenHour > 12)
{
clockScreenHour = clockScreenHour - 12;
myGLCD.setFont(DisplayFont);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("PM", 5, 10);
}
else
{
myGLCD.setFont(DisplayFont);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.print("AM", 5, 10);
}
myGLCD.setFont(ClockFont);
myGLCD.setColor(0, 0, 0);
myGLCD.setBackColor(255, 255, 255);
myGLCD.print(":", 128, 80);
clockScreenMinute = now.minute();
if (clockScreenHour < 10)
{
myGLCD.printNumI(clockScreenHour, 64, 80);
}
else
{
myGLCD.printNumI(clockScreenHour, 0, 80);
}
if (now.minute() < 10)
{
myGLCD.print("0", 192, 80);
myGLCD.printNumI(clockScreenMinute, 256, 80);
}
else
{
myGLCD.printNumI(clockScreenMinute, 192, 80);
}
timeChange = false;
}
if (now.hour() != clockScreenHour || now.minute() != clockScreenMinute)
{
timeChange = true;
}
rtcClockScreenSeconds();
}
void rtcClockScreenSeconds()
{
int clockScreenSeconds;
boolean secondChange = true;
boolean secondRestart = false;
DateTime now = rtc.now();
clockScreenSeconds = now.second();
myGLCD.setFont(DisplayFont);
if (secondChange)
{
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(0, 0, 0);
if (secondRestart)
{
myGLCD.setColor(0, 0, 0);
myGLCD.fillRect(220, 190, 319, 239);
myGLCD.setColor(255, 255, 255);
myGLCD.setBackColor(0, 0, 0);
myGLCD.printNumI(00, 220, 190);
secondRestart = false;
}
if (clockScreenSeconds < 10)
{
myGLCD.printNumI(0, 220, 190);
myGLCD.printNumI(clockScreenSeconds, 268, 190);
}
else
{
myGLCD.printNumI(clockScreenSeconds, 220, 190);
}
secondChange = false;
}
if (now.second() != clockScreenSeconds) secondChange = true;
if (clockScreenSeconds == 0) secondRestart = true;
}
//Subroutine to display date values on datescreen
void rtcDateScreenDisplay()
{
boolean dateChange = false;
DateTime now = rtc.now();
if (now.year())
{
}
}
//Subroutine to adjust clock values when a date change is initiated
int rtcSetDate(int yearIn, int monthIn, int dayIn)
{
DateTime now = rtc.now();
rtchour = now.hour();
rtcmin = now.minute();
rtcsec = now.second();
rtc.adjust(DateTime(yearIn, monthIn, dayIn, rtchour, rtcmin, rtcsec));
}
//Subroutine to adjust clock value when a time change is initiated
int rtcSetClock(int hourIn, int minuteIn)
{
DateTime now = rtc.now();
rtcyear = now.year();
rtcmonth = now.month();
rtcday = now.day();
rtcsec = 0;
rtc.adjust(DateTime(rtcyear, rtcmonth, rtcday, hourIn, minuteIn, rtcsec));
}