Arduino Multiple Clock Project - USB clock synch?

I am making a wall clock and an alarm clock that will not always be connected to the computer. The computer will only be used as needed to re-synch the time when it is too far out of bounds.

The solution is the following program sketch (for the PCF8523). To use with the DS1307, a person just needs to change the declare instance to DS1307 instead of PCF8523. This sketch looks for 3 integers separated by commas and then a line return. I used Processing to create the matching computer signal.

/*
   This matches the processing Clock_Synch sketch
*/


// Date and time functions using a PCF8523 RTC connected via I2C and Wire lib
// Display is Adafruit 7seg with HT16K33 backpack.
// Arduino Uno compatible micro-controller
// V2 adds serial clock setting

#include <Wire.h>
#include "RTClib.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"


// Set to false to display time in 12 hour format, or true to use 24 hour:
#define TIME_24_HOUR      true

// I2C address of the display.  Stick with the default address of 0x70
// unless you've changed the address jumpers on the back of the display.
#define DISPLAY_ADDRESS   0x70


// Create display and DS1307 objects.  These are global variables that
// can be accessed from both the setup and loop function below.
Adafruit_7segment clockDisplay = Adafruit_7segment();
RTC_PCF8523 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// Keep track of the hours, minutes, seconds displayed by the clock.
// Start off at 0:00:00 as a signal that the time should be read from
// the DS1307 to initialize it.
int hours = 0;
int minutes = 0;
int seconds = 0;

// Remember if the colon was drawn on the display so it can be blinked
// on and off every second.
bool blinkColon = true;
String inputString = "";         // a String to hold incoming data
bool stringComplete = false;  // whether the string is complete
unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 1000;           // interval
byte hr = hours;
byte mi = minutes;
byte sec = seconds;


void setup () {

  while (!Serial); // for Leonardo/Micro/Zero

  Serial.begin(115200);

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  // Setup the display.
  clockDisplay.begin(DISPLAY_ADDRESS);

  //if (! rtc.initialized()) {  //Commented out to stop the time from reseting
  //Serial.println("RTC is NOT running!");
  // following line sets the RTC to the date & time this sketch was compiled
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // January 21, 2014 at 3am you would call:
  //rtc.adjust(DateTime(2017, 4, 1, 12, 0, 0));
  //}
  inputString.reserve(20);
}

void loop () {
  recv();
  loopy();
}

void loopy() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    // This gets the time and sends it out via serial port (USB to computer)

    DateTime now = rtc.now();

    cerial();


    // Now set the hours and minutes.
    if (!stringComplete) {
      hours = now.hour();
      minutes = now.minute();
      seconds = now.second();


      // Show the time on the display by turning it into a numeric
      // value, like 3:30 turns into 330, by multiplying the hour by
      // 100 and then adding the minutes.
      int displayValue = hours * 100 + minutes;

      // Do 24 hour to 12 hour format conversion when required.
      if (!TIME_24_HOUR) {
        // Handle when hours are past 12 by subtracting 12 hours (1200 value).
        if (hours > 12) {
          displayValue -= 1200;
        }
        // Handle hour 0 (midnight) being shown as 12.
        else if (hours == 0) {
          displayValue += 1200;
        }
      }
      clockDisplay.setBrightness(2);
      // Now print the time value to the display.
      clockDisplay.print(displayValue, DEC);

      // Add zero padding when in 24 hour mode and it's midnight.
      // In this case the print function above won't have leading 0's
      // which can look confusing.  Go in and explicitly add these zeros.
      if (TIME_24_HOUR && hours == 0) {
        // Pad hour 0.
        clockDisplay.writeDigitNum(1, 0);
        // Also pad when the 10's minute is 0 and should be padded.
        if (minutes < 10) {
          clockDisplay.writeDigitNum(2, 0);
        }
      }

      // Blink the colon by flipping its value every loop iteration
      // (which happens every second).
      /* Um, no blink colon
        blinkColon = !blinkColon;
      */
      clockDisplay.drawColon(blinkColon);

      // Now push out to the display the new values that were set above.
      clockDisplay.writeDisplay();

      // Pause for a second for time to elapse.  This value is in milliseconds
      // so 1000 milliseconds = 1 second.
    }
  }
}


void recv() {
  // print the string when a newline arrives:
  if (stringComplete) {
    
    Serial.print(hr, DEC);
    Serial.print(mi, DEC);
    Serial.println(sec, DEC);
    rtc.adjust(DateTime(2021, 5, 6, hr, mi, sec));
    cerial();
    // clear the string:
    inputString = "";
    stringComplete = false;
  }
}

/*
  SerialEvent occurs whenever a new data comes in the hardware serial RX. This
  routine is run between each time loop() runs, so using delay inside loop can
  delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
  while (Serial.available() > 0) {

    // look for the next valid integer in the incoming serial stream:
    hr = Serial.parseInt();
    // do it again:
    mi = Serial.parseInt();
    // do it again:
    sec = Serial.parseInt();

    // look for the newline. That's the end of your sentence:
    if (Serial.read() == '\n') {
      // print the three numbers in one string as hexadecimal:
      Serial.print(hr, DEC);
      Serial.print(mi, DEC);
      Serial.println(sec, DEC);

    }
    stringComplete = true;
  }
}


void cerial() {
  DateTime now = rtc.now();
  
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(" (");
  Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  Serial.print(") ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();
}