Question about an example from the "Using USB Serial Communication" help page
Hello,
I don't understand why there is a sync function included in the code below, from the Using USB Serial Communication page. Is it required for the data reception?
Hello,
I don't understand why there is a sync function included in the code below, from the Using USB Serial Communication page. Is it required for the data reception?
Code:
// This will always work on Teensy, does not depend on buffer size
boolean getNumbersFromSerial() {
int count=0;
char buf[11];
while (count < 11) {
if (Serial.available()) { // receive all 11 bytes into "buf"
buf[count++] = Serial.read();
}
}
if (buf[0] == '@') {
time_t pctime = 0;
for(int i=1; i < 11; i++) {
char c = buf[i];
if (c >= '0' && c <= '9') {
pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
}
}
pctime += 10;
DateTime.sync(pctime); // Sync clock to the time received
return true; // return true if time message received
}
return false; //if no message return false
}