Master clock for small clock network

Take this out, is is not needed, the processor will handle overflow arithmetic of unsigned long integers properly. You will not notice it for a while, but this will throw off the time slightly at 49 day intervals.

  // =================== OVERFLOW CHECK ==========================
  //If TimeMain value became smaller then TimeMain_last we encounterd an overflow of millis register. Now we need to reset TimeMain_last.
  //Note: Manual reset of current minute and time adjust is likely needed after overflow reset.

  if (TimeMain < TimeMain_last) {
    TimeMain_last = TimeMain;
  }

Try changing the main timing loop to this:

  TimeMain = millis(); //Main timer

  if (TimeMain - TimeMain_last >= TimeMain_value) {
    TimeMain_last += TimeMain_value;
    pulseGo = true;
    TimePulse_last = millis(); // write actual time used for count pulse lenght delay
  }
1 Like