TimeRTC
From: https://github.com/thijse/Arduino-Code-and-Libraries/blob/master/Libraries/Time/Examples/TimeRTC/TimeRTC.pde
/*H*******************************************************
* TimeRTC.pde
* example code illustrating Time library with Real Time Clock.
********************************************************/
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
//************************* DEFINES ************************************
//************************* PROTOTYPES ************************************
//************************* VARIABLES ************************************
/*F********************************************************************
*
**********************************************************************/
void
setup()
{
Serial.begin( 9600 );
setSyncProvider( RTC.get ); // the function to get the time from the RTC
if( timeStatus()!= timeSet )
Serial.println( "Unable to sync with the RTC" );
else
Serial.println( "RTC has set the system time" );
}
/*F********************************************************************
*
**********************************************************************/
void
loop()
{
digitalClockDisplay();
delay( 1000 );
}
/*F********************************************************************
* digital clock display of the time
**********************************************************************/
void
digitalClockDisplay()
{
Serial.print( hour() );
printDigits( minute() );
printDigits( second() );
Serial.print( " " );
Serial.print( day() );
Serial.print( " " );
Serial.print( month() );
Serial.print( " " );
Serial.print( year() );
Serial.println();
}
/*F********************************************************************
* digital clock display: prints preceding colon and leading 0
**********************************************************************/
void
printDigits( int digits )
{
Serial.print( ":" );
if( digits < 10 )
Serial.print( '0' );
Serial.print( digits );
}