RTC

Please use M5.RTC.begin() to initialize RTC related functions before using

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;

setTime()

Syntax:

void setTime(rtc_time_t *time)

Description:

Set RTC Time Struct

getTime()

Syntax:

void getTime(rtc_time_t *time)

Description:

Get RTC Time Struct

setDate()

Syntax:

void setDate(rtc_date_t *date)

Description:

Set RTC Date Struct

getDate()

Syntax:

void getDate(rtc_date_t *date)

Description:

Get RTC Date Struct

Example:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);

rtc_time_t RTCtime;
rtc_date_t RTCDate;

char timeStrbuff[64];

void flushTime(){
    M5.RTC.getTime(&RTCtime);
    M5.RTC.getDate(&RTCDate);
    
    sprintf(timeStrbuff,"%d/%02d/%02d %02d:%02d:%02d",
                        RTCDate.year,RTCDate.mon,RTCDate.day,
                        RTCtime.hour,RTCtime.min,RTCtime.sec);
                                         
    canvas.drawString(timeStrbuff, 0, 0);
    canvas.pushCanvas(100,200,UPDATE_MODE_DU4);
}

void setupTime(){
  
  RTCtime.hour = 23;
  RTCtime.min = 33;
  RTCtime.sec = 33;
  M5.RTC.setTime(&RTCtime);
  
  RTCDate.year = 2020;
  RTCDate.mon = 11;
  RTCDate.day = 27;
  M5.RTC.setDate(&RTCDate);
}

void setup() {

    M5.begin();
    M5.EPD.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(400, 300);
    canvas.setTextSize(3);
    setupTime();
}

void loop() {
  flushTime();
  delay(1000);
}

shutdown()

function overload-1:

Power off and wake up again via PWR button

void shutdown()

function overload-2:

Turn off the power and wake up the device via RTC at the end of the delay based on the number of seconds of incoming delay.

int shutdown( int seconds )

function overload-3:

Turn off the power, pass in the RTC time structure that specifies a certain point in time, and wake up the device via RTC when the hours, minutes, and seconds of that time are met.

int shutdown( const rtc_time_t &RTC_TimeStruct)

function overload-4:

Turn off the power, pass in the RTC time structure specified for a certain point in time, and wake up the device by RTC when the week number, day number, and time of that point in time match at the same time.

int shutdown( const rtc_date_t &RTC_DateStruct, const rtc_time_t &RTC_TimeStruct)

Example:

#include <M5EPD.h>

M5EPD_Canvas canvas(&M5.EPD);

void setup()
{
    M5.begin();
    M5.EPD.SetRotation(90);
    M5.TP.SetRotation(90);
    M5.EPD.Clear(true);
    M5.RTC.begin();
    canvas.createCanvas(540, 960);
    canvas.setTextSize(3);
    canvas.drawString("Press PWR Btn for sleep!", 45, 350);
    canvas.drawString("after 5 sec wakeup!", 70, 450);
    canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
    
    
}

void loop()
{
    if(M5.BtnP.wasPressed()){
        
        canvas.drawString("I'm going to sleep.zzzZZZ~", 45, 550);
        canvas.pushCanvas(0,0,UPDATE_MODE_DU4);
        delay(1000);
        M5.shutdown(5);
    }
    M5.update();
    delay(100);
}
On This Page