Hi!
I'm new to Arduino. I wrote a sketch using the Time library (which works great, though my DS1307 seems to run very fast -- that's another topic...) and I became curious and dug into the library a bit to see how it works. I think I mostly get what is going on, but I can't figure out how it handles the situation where millis() rolls back to zero. Can somebody explain it to me?
Here's the meat & potatoes function that gets the time. Doesn't the same value of sysTime just get returned over and over again since it's not being incremented anymore? What am I screwing up? I'm new to C/C++ so hit me with the cluestick please.
time_t now(){
while( millis() - prevMillis >= 1000){
sysTime++;
prevMillis += 1000;
#ifdef TIME_DRIFT_INFO
sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift
#endif
}
if(nextSyncTime <= sysTime){
if(getTimePtr != 0){
time_t t = getTimePtr();
if( t != 0)
setTime(t);
else
Status = (Status == timeNotSet) ? timeNotSet : timeNeedsSync;
}
}
return sysTime;
}
Thanks!