This repository has been archived on 2020-09-09. You can view files and clone it, but cannot push or open issues or pull requests.
arduino_universal_serial_ad.../Libraries/AdafruitLogger/SoftRTClib/examples/ds1307Wire/ds1307Wire.pde

38 lines
870 B
Plaintext
Raw Normal View History

// Warning: set DS_RTC_USE_WIRE nonzero in SoftRTClib.h
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include <SoftRTClib.h>
#if !DS_RTC_USE_WIRE
#error set DS_RTC_USE_WIRE nonzero in SoftRTClib.h
#endif // DS_RTC_USE_WIRE
RTC_DS1307 RTC;
void setup () {
Serial.begin(9600);
Wire.begin();
}
void loop () {
DateTime now = RTC.now();
now.printIsoDateTime(&Serial);
Serial.println();
Serial.print(" since midnight 1/1/1970 = ");
Serial.print(now.unixtime());
Serial.print("s = ");
Serial.print(now.unixtime() / 86400L);
Serial.println("d");
// calculate a date which is 7 days and 30 seconds into the future
DateTime future (now.unixtime() + 7 * 86400L + 30);
Serial.print(" now + 7d + 30s: ");
future.printIsoDateTime(&Serial);
Serial.println();
Serial.println();
delay(3000);
}