The Planted Tank Forum - View Single Post - Guide: Arduino based LED controller for Current Satellite LED+
View Single Post
post #337 of (permalink) Old 08-30-2013, 05:16 PM
Algae Grower
Join Date: Oct 2010
Location: Mississippi
Posts: 119
Originally Posted by mistergreen View Post
Yeah, does it do only once on setup()?
Yes, there is no need to call it more than once, which is done in setup() here, and there is no need to call setSyncInterval() at all unless you want to change the default 300 second (5 minute) sync interval.

The time library automatically resyncs the Arduino clock to the RTC every 5 minutes by default with the code as is. It checks nextSyncTime in the now() function to see if the interval has passed. now() is called by hour(), minute() and etc every time you call for a time.

time_t now() {
  while (millis() - prevMillis >= 1000){      
    prevMillis += 1000;    
    sysUnsyncedTime++; // this can be compared to the synced time to measure long term drift     
  if (nextSyncTime <= sysTime) {  // See if sync interval has passed (every 300 seconds by default)
    if (getTimePtr != 0) {        // Did the user set a pointer to their own function?
      time_t t = getTimePtr();    // Yes, so call their function to get the time
      if (t != 0) {               // Successfull?
        setTime(t);               // Yes, so go set the Arduino's time using this time
      } else {
        nextSyncTime = sysTime + syncInterval;
        Status = (Status == timeNotSet) ?  timeNotSet : timeNeedsSync;
  return (time_t)sysTime;
Our code calls setSyncProvider(), which sets getTimePtr to a pointer to our syncProvider() function, which returns a time from our RTC. So without any modifications, the Arduino's clock is sync'ed to the RTC's clock every 300 seconds by default. I'd think changing the sync interval from once every 5 minutes to once every 24 hours would make the clock less accurate, so I'd leave it alone.

So either there is something wrong with Caver's RTC, or he has removed the calls to hour(), minute(), and second() in SendCode() and loop(). If you don't fetch a time every so often, then it doesn't get sync'ed.

Last edited by Dahammer; 08-30-2013 at 05:33 PM. Reason: typo
Dahammer is offline  
For the best viewing experience please update your browser to Google Chrome