SummaryRTC (Real Time Clock) library supports built-in DS1307 clock.
Include#include <RTC.h>
Structuresstruct RTCTime
{
uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t day;
uint8_t month;
uint8_t year;
uint8_t dayOfWeek;
};
ProceduresRTC.set(year, month, day, dayOfWeek, hour, minute, second)RTC.set(tm)RTC.set allows you set current date and time in DS1307 chip. If you use a backup battery, the time in the chip will be saved, otherwise you have to set time always after power cut.
Example #1
#include <RTC.h>
void setup()
{
// Set 2009-05-11 14:10:00
RTC.set(9, 5, 11, 0, 14, 10, 0);
}
Example #2
FunctionsRTCTime RTC.time()Allows you to get the current time (returns RTCTime structure). You need to set the time before using that.
Example #1
#include <RTC.h>
void setup()
{
Serial.begin(9600);
RTCTime tm = RTC.time();
// Print current hour
Serial.println(tm.hour, DEC);
}
DownloadYou can download the RTC library from our Libraries repository. AdvancedAddressingThe RTC chip communicates with processor using I2C protocol. The address of DS1307 is hard-written as DS1307_I2C_ADDRESS macro constant (in RTC.h file) - default it is 0x68. If you need you can change value using a code similar to that one. Example #1 (advanced) // ..
#include <RTC.h>
// Change address
#undef DS1307_I2C_ADDRESS
#define DS1307_I2C_ADDRESS 0x53
// ... |
