2 * TimeSerialDateStrings.pde
3 * example code illustrating Time library date strings
5 * This sketch adds date string functionality to TimeSerial.pde
11 #define TIME_MSG_LEN 11 // time sync to PC is HEADER followed by unix time_t as ten ascii digits
12 #define TIME_HEADER 'T' // Header tag for serial time sync message
13 #define TIME_REQUEST 7 // ASCII bell character requests a time sync message
17 setSyncProvider( requestSync); //set function to call when sync required
18 Serial.println("Waiting for sync message");
22 if(Serial.available() )
26 if(timeStatus()!= timeNotSet)
28 digitalClockDisplay();
33 void digitalClockDisplay(){
34 // digital clock display of the time
36 printDigits(minute());
37 printDigits(second());
39 Serial.print(dayStr(weekday()));
43 Serial.print(monthShortStr(month()));
49 void printDigits(int digits){
50 // utility function for digital clock display: prints preceding colon and leading 0
57 void processSyncMessage() {
58 // if time sync available from serial port, update time and return true
59 while(Serial.available() >= TIME_MSG_LEN ){ // time message consists of a header and ten ascii digits
60 char c = Serial.read() ;
62 if( c == TIME_HEADER ) {
64 for(int i=0; i < TIME_MSG_LEN -1; i++){
66 if( c >= '0' && c <= '9'){
67 pctime = (10 * pctime) + (c - '0') ; // convert digits to a number
70 setTime(pctime); // Sync Arduino clock to the time received on the serial port
77 Serial.print(TIME_REQUEST,BYTE);
78 return 0; // the time will be sent later in response to serial mesg