TinyRTClib.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Code by JeeLabs http://news.jeelabs.org/code/
  2. // Released to the public domain! Enjoy!
  3. // No changes from RTClib.h
  4. #ifndef _RTCLIB_H_
  5. #define _RTCLIB_H_
  6. // Simple general-purpose date/time class (no TZ / DST / leap second handling!)
  7. class DateTime {
  8. public:
  9. DateTime (uint32_t t =0);
  10. DateTime (uint16_t year, uint8_t month, uint8_t day,
  11. uint8_t hour =0, uint8_t min =0, uint8_t sec =0);
  12. DateTime (const char* date, const char* time);
  13. uint16_t year() const { return 2000 + yOff; }
  14. uint8_t month() const { return m; }
  15. uint8_t day() const { return d; }
  16. uint8_t hour() const { return hh; }
  17. uint8_t minute() const { return mm; }
  18. uint8_t second() const { return ss; }
  19. uint8_t dayOfWeek() const;
  20. // 32-bit times as seconds since 1/1/2000
  21. long secondstime() const;
  22. // 32-bit times as seconds since 1/1/1970
  23. uint32_t unixtime(void) const;
  24. protected:
  25. uint8_t yOff, m, d, hh, mm, ss;
  26. };
  27. // RTC based on the DS1307 chip connected via I2C and the Wire library
  28. class RTC_DS1307 {
  29. public:
  30. static uint8_t begin(void);
  31. static void adjust(const DateTime& dt);
  32. uint8_t isrunning(void);
  33. static DateTime now();
  34. };
  35. // RTC using the internal millis() clock, has to be initialized before use
  36. // NOTE: this clock won't be correct once the millis() timer rolls over (>49d?)
  37. class RTC_Millis {
  38. public:
  39. static void begin(const DateTime& dt) { adjust(dt); }
  40. static void adjust(const DateTime& dt);
  41. static DateTime now();
  42. protected:
  43. static long offset;
  44. };
  45. #endif // _RTCLIB_H_