Before using RTC-related functions, please initialize with M5.begin()
.
typedef struct RTC_Time{
int8_t Hours;
int8_t Minutes;
int8_t Seconds;
RTC_Time() : Hours(),Minutes(),Seconds(){}
RTC_Time(int8_t h,int8_t m,int8_t s) : Hours(h),Minutes(m),Seconds(s){}
} RTC_TimeTypeDef;
typedef struct RTC_Date
{
int8_t WeekDay;
int8_t Month;
int8_t Date;
int16_t Year;
RTC_Date() : WeekDay(),Month(),Date(),Year(){}
RTC_Date(int8_t w,int8_t m,int8_t d, int16_t y) : WeekDay(w),Month(m),Date(d),Year(y){}
} RTC_DateTypeDef;
Description:
Sets the time of a structure variable.
Syntax:
void SetTime(RTC_TimeTypeDef* RTC_TimeStruct)
Example:
#include "M5CoreInk.h"
Ink_Sprite InkPageSprite(&M5.M5Ink);
RTC_TimeTypeDef RTCtime;
void setup() {
M5.begin();
if (!M5.M5Ink.isInit()) {
Serial.printf("Ink Init failed");
while (1) delay(100);
}
M5.M5Ink.clear();
delay(1000);
RTCtime.Hours = 23;
RTCtime.Minutes = 33;
RTCtime.Seconds = 33;
M5.rtc.SetTime(&RTCtime);
}
void loop(){}
Description:
Gets the time from a structure.
Syntax:
void GetTime(RTC_TimeTypeDef* RTC_TimeStruct)
Example:
#include "M5CoreInk.h"
Ink_Sprite InkPageSprite(&M5.M5Ink);
RTC_TimeTypeDef RTCtime;
RTC_DateTypeDef RTCDate;
void setup() {
M5.begin();
if (!M5.M5Ink.isInit()) {
Serial.printf("Ink Init failed");
while (1) delay(100);
}
M5.M5Ink.clear();
delay(1000);
// create ink refresh Sprite
if (InkPageSprite.createSprite(0, 0, 200, 200, true) != 0) {
Serial.printf("Ink Sprite create failed");
}
RTCtime.Hours = 23;
RTCtime.Minutes = 33;
RTCtime.Seconds = 33;
M5.rtc.SetTime(&RTCtime);
}
void loop() {
char timeStrbuff[64];
M5.rtc.GetTime(&RTCtime);
sprintf(timeStrbuff, " %02d:%02d:%02d", RTCtime.Hours, RTCtime.Minutes,
RTCtime.Seconds);
InkPageSprite.drawString(10, 100, timeStrbuff);
InkPageSprite.pushSprite();
delay(15000);
}
Description:
Sets the date of a structure variable.
Syntax:
void SetDate(RTC_TimeTypeDef* RTC_DateStruct)
Example:
#include "M5CoreInk.h"
Ink_Sprite InkPageSprite(&M5.M5Ink);
RTC_DateTypeDef RTCDate;
void setup() {
M5.begin();
if (!M5.M5Ink.isInit()) {
Serial.printf("Ink Init failed");
while (1) delay(100);
}
M5.M5Ink.clear();
delay(1000);
RTCDate.Year = 2020;
RTCDate.Month = 11;
RTCDate.Date = 6;
M5.rtc.SetDate(&RTCDate);
}
void loop() {}
Description:
Gets the date from a structure variable.
Syntax:
void GetDate(RTC_TimeTypeDef* RTC_DateStruct)
Example:
#include "M5CoreInk.h"
Ink_Sprite InkPageSprite(&M5.M5Ink);
RTC_TimeTypeDef RTCtime;
RTC_DateTypeDef 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.Month,RTCDate.Date,
RTCtime.Hours,RTCtime.Minutes,RTCtime.Seconds);
InkPageSprite.drawString(
10,100,timeStrbuff);
InkPageSprite.pushSprite();
}
void setupTime(){
RTCtime.Hours = 23;
RTCtime.Minutes = 33;
RTCtime.Seconds = 33;
M5.rtc.SetTime(&RTCtime);
RTCDate.Year = 2020;
RTCDate.Month = 11;
RTCDate.Date = 6;
M5.rtc.SetDate(&RTCDate);
}
void setup() {
M5.begin();
if( !M5.M5Ink.isInit()){
Serial.printf("Ink Init failed");
while (1) delay(100);
}
M5.M5Ink.clear();
delay(1000);
// create ink refresh Sprite
if( InkPageSprite.createSprite(0,0,200,200,true) != 0 ){
Serial.printf("Ink Sprite create failed");
}
setupTime();
}
void loop() {
flushTime();
delay(15000);
}
Turns off the power, the device can be awakened again by pressing the PWR button.
void shutdown()
Turns off the power, and after a delay defined by the passed seconds, the device is awakened by the RTC.
int shutdown( int seconds )
Turns off the power, and at a specific time point defined by an RTC time structure, the device is awakened by the RTC when the hour
, minute
, and second
match.
int shutdown( const RTC_TimeTypeDef &RTC_TimeStruct)
Turns off the power, and at a specific time point defined by an RTC time and date structure, the device is awakened by the RTC when the week number
, day
, and time
simultaneously match.
int shutdown( const RTC_DateTypeDef &RTC_DateStruct, const RTC_TimeTypeDef &RTC_TimeStruct)
Example:
#include "M5CoreInk.h"
void setup(){
M5.begin();
digitalWrite(LED_EXT_PIN,LOW);
M5.update();
M5.M5Ink.clear();
delay(500);
}
void loop(){
if( M5.BtnPWR.wasPressed()){
Serial.printf("Btn %d was pressed \r\n",BUTTON_EXT_PIN);
digitalWrite(LED_EXT_PIN,LOW);
M5.shutdown(5);
}
M5.update();
}