2021-10-02 07:18:21 +02:00
|
|
|
#include "RTC.h"
|
|
|
|
#include "SdFat.h"
|
|
|
|
|
|
|
|
RTC_DS3231 rtc;
|
|
|
|
|
|
|
|
// Start Time
|
|
|
|
void RTCStart() {
|
|
|
|
// Start RTC
|
|
|
|
if (! rtc.begin()) {
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set RTC Date/Time of Sketch Build if it lost battery power
|
|
|
|
// After initial setup it would have lost battery power ;)
|
|
|
|
if (rtc.lostPower()) {
|
2021-10-14 09:53:07 +02:00
|
|
|
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
|
2021-10-02 07:18:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Date/Time Callback Funtion
|
|
|
|
// Callback for file timestamps
|
|
|
|
void dateTime(uint16_t* date, uint16_t* time) {
|
|
|
|
DateTime now = rtc.now();
|
|
|
|
|
|
|
|
// Return date using FAT_DATE macro to format fields
|
|
|
|
*date = FAT_DATE(now.year(), now.month(), now.day());
|
|
|
|
|
|
|
|
// Return time using FAT_TIME macro to format fields
|
|
|
|
*time = FAT_TIME(now.hour(), now.minute(), now.second());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************
|
|
|
|
RTC Time Stamp Setup
|
|
|
|
Call in any other script
|
|
|
|
*****************************************/
|
|
|
|
// Format a Date/Time stamp
|
|
|
|
String RTCStamp() {
|
|
|
|
// Set a format
|
|
|
|
char dtstamp[] = "DDMMMYYYY hh:mm:ssAP";
|
2021-10-14 09:53:07 +02:00
|
|
|
|
2021-10-02 07:18:21 +02:00
|
|
|
// Get current Date/Time
|
|
|
|
DateTime now = rtc.now();
|
|
|
|
|
|
|
|
// Convert it to a string and caps lock it
|
|
|
|
String dts = now.toString(dtstamp);
|
|
|
|
dts.toUpperCase();
|
2021-10-14 09:53:07 +02:00
|
|
|
|
2021-10-02 07:18:21 +02:00
|
|
|
// Print results
|
|
|
|
return dts;
|
|
|
|
}
|