Before using RTC-related functions, please initialize with M5.begin()
typedef struct RTC_Time { int8_t hour; int8_t min; int8_t sec; RTC_Time() : hour(), min(), sec() {} RTC_Time(int8_t h, int8_t m, int8_t s) : hour(h), min(m), sec(s) {}} rtc_time_t; typedef struct RTC_Date { int8_t week; int8_t mon; int8_t day; int16_t year; RTC_Date() : week(), mon(), day(), year() {} RTC_Date(int8_t w, int8_t m, int8_t d, int16_t y) : week(w), mon(m), day(d), year(y) {}} rtc_date_t;
Description:
Initializes RTC
M5.RTC.begin()
to initialize before using RTC-related functionsSyntax:
void begin()
Description:
Sets the time of a structure variable
Syntax:
void setTime(const rtc_time_t *time)
Example:
#include <M5EPD.h> M5EPD_Canvas canvas(&M5.EPD);rtc_time_t RTCtime; void setup() { M5.begin(); M5.EPD.SetRotation(90); M5.EPD.Clear(true); M5.RTC.begin(); canvas.createCanvas(500, 300); canvas.setTextSize(3); RTCtime.hour = 00; RTCtime.min = 00; RTCtime.sec = 00; M5.RTC.setTime(&RTCtime);} void loop() {}
Description:
Gets the time from a structure
Syntax:
void getTime(rtc_time_t *time)
Example:
#include <M5EPD.h> M5EPD_Canvas canvas(&M5.EPD); rtc_time_t RTCtime;char timeStrbuff[64]; void setup() { M5.begin(); M5.EPD.SetRotation(90); M5.EPD.Clear(true); M5.RTC.begin(); canvas.createCanvas(500, 300); canvas.setTextSize(3); RTCtime.hour = 00; RTCtime.min = 00; RTCtime.sec = 00; M5.RTC.setTime(&RTCtime);} void loop() { M5.RTC.getTime(&RTCtime); sprintf(timeStrbuff, "%02d:%02d:%02d", RTCtime.hour, RTCtime.min, RTCtime.sec); canvas.drawString(timeStrbuff, 0, 0); canvas.pushCanvas(200, 200, UPDATE_MODE_DU4); delay(2000);}
Description:
Sets the date of a structure variable
Syntax:
void setDate(const rtc_date_t *date)
Example:
#include <M5EPD.h> M5EPD_Canvas canvas(&M5.EPD);rtc_date_t RTCDate; void setup() { M5.begin(); M5.EPD.SetRotation(90); M5.EPD.Clear(true); M5.RTC.begin(); canvas.createCanvas(500, 300); canvas.setTextSize(3); RTCDate.year = 2020; RTCDate.mon = 11; RTCDate.day = 27; M5.RTC.setDate(&RTCDate);} void loop() {}
Description:
Gets the date from a structure
Syntax:
void getDate(rtc_date_t *date)
Example:
#include <M5EPD.h> M5EPD_Canvas canvas(&M5.EPD);rtc_date_t RTCDate;char timeStrbuff[64]; void setup() { M5.begin(); M5.EPD.SetRotation(90); M5.EPD.Clear(true); M5.RTC.begin(); canvas.createCanvas(500, 300); canvas.setTextSize(3); RTCDate.year = 2020; RTCDate.mon = 11; RTCDate.day = 27; M5.RTC.setDate(&RTCDate);} void loop() { M5.RTC.getDate(&RTCDate); sprintf(timeStrbuff, "%02d:%02d:%02d", RTCDate.year, RTCDate.mon, RTCDate.day); canvas.drawString(timeStrbuff, 0, 0); canvas.pushCanvas(150, 200, UPDATE_MODE_DU4); delay( 10000);}
Description:
Sets an interrupt alarm
Function Prototypes:
int SetAlarmIRQ(int afterSeconds)
int setAlarmIRQ(const rtc_time_t &time)
int setAlarmIRQ(const rtc_date_t &date, const rtc_time_t &time)
Example:
#include <M5Core2.h> RTC_TimeTypeDef TimeStruct;void setup() { M5.begin(); M5.Lcd.println("RTC SetAlarmIQR"); TimeStruct.Hours = 18; TimeStruct.Minutes = 56; TimeStruct.Seconds = 10; M5.Rtc.SetTime(&TimeStruct);} void loop() { M5.update(); M5.Rtc.GetTime(&TimeStruct); M5.Lcd.setCursor(0, 15); M5.Lcd.printf("Time: %02d : %02d : %02d/n",TimeStruct.Hours, TimeStruct.Minutes, TimeStruct.Seconds); if(M5.BtnA.wasPressed()){ M5.Lcd.println("M5Core2 Will Close, Restore After 5 seconds "); delay(2000); M5.Rtc.clearIRQ(); M5.Rtc.SetAlarmIRQ(5); delay(10); M5.Axp.PowerOff(); }}
Description:
Clears the interrupt request
Syntax:
void clearIRQ()
Description:
Disables the interrupt request
Syntax:
void disableIRQ()