alvarojusten:
Hello mem,
I needed to use DS1307 Real-Time Clock on a project and saw the Time library, but I thought it was too big for what I needed (just to know day, month, year, hour, minute and second from DS1307), so I decided to create a new, simple library to achieve this task and its code is at GitHub:I think we should integrate it, maybe creating a "driver interface" (just some conventions) so we can create drivers for many RTC chips and use the same code. What do you think?
Other thing I think that should be changed in Time library is the namespace of functions. Maybe using Time.hour(), Time.day() etc. instead of directly hour(), day() etc.
Hi alvarojusten
Thank you for sharing your library. I have seen many DS1037 Arduino libraries and yours is one of the simplest (that’s a compliment). It does use less flash memory than the Time library but it actually seems to use more data (your sketch uses 540 bytes of RAM, the Time library code posted below uses 482 bytes of RAM).
/*
* A simple sketch to display time from a DS1307 RTC
*
*/
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h> // a basic DS1307 library that returns time as a time_t
char dateTime[20];
void setup() {
Serial.begin(9600);
}
void loop()
{
setTime(RTC.get());
sprintf(dateTime, "%4d-%02d-%02d %02d:%02d:%02d", year(),
month(), day(), hour(),minute(), second()) ;
Serial.print(dateTime);
Serial.print(" - day of week: ");
Serial.println(dayStr(weekday()));
delay(1000);
}
Here are some advantage of using the Time library version:
- You can easily calculate the difference between two times
- The time format is based on a standard that almost every programming platform can handle
- The same sketch code can be used with a selection of time sources such as RTC, NTP( internet time standards), Radio Clocks, GPS …
- You can use the TimeAlarms library to add timers and time of day alarms.