RTC

Begin()

Function:

Initialize RTC

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

Syntax:

void begin()

setTime()

Function:

Set structure variable time

Syntax:

void setTime(const rtc_time_t *time)

setDate()

Function:

Set structure variable date

Syntax:

void setDate(const rtc_date_t *date)

getTime()

Function:

Get structure time

Syntax:

void getTime(rtc_time_t *time)

getDate()

Function:

Get structure variable date

Syntax:

void getDate(rtc_date_t *date)

Example:

#include <M5EPD.h>
rtc_time_t RTCtime;
rtc_date_t RTCDate;
char timeStrbuff[64];
M5EPD_Canvas canvas(&M5.EPD);

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);
}

SetAlarmIRQ()

Function:

Set interrupt clock

Syntax:

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();
  }
}

clearIRQ()

Function:

Clear interrupt request

Syntax:

void clearIRQ()

disableIRQ()

Function:

Close interrupt request

Syntax:

void disableIRQ()

On This Page