pdf-icon

RTC

SetTime()

Description:

Sets the time of a structure variable

Syntax:

void SetTime(RTC_TimeTypeDef* RTC_TimeStruct)

Example:

#include <M5StickC.h>

RTC_TimeTypeDef TimeStruct;
void setup() {
  M5.begin();

  TimeStruct.Hours   = 18;
  TimeStruct.Minutes = 56;
  TimeStruct.Seconds = 10;
  M5.Rtc.SetTime(&TimeStruct);
}
void loop(){};

GetTime()

Description:

Gets the time from a structure

Syntax:

void GetTime(RTC_TimeTypeDef* RTC_TimeStruct)

Example:


#include <M5StickC.h>

RTC_TimeTypeDef TimeStruct;
void setup() {
  M5.begin();
  M5.Lcd.setRotation(3);
  M5.Lcd.fillScreen(BLACK);
 
  M5.Lcd.setTextSize(1);
  M5.Lcd.setCursor(40, 0, 2);
  M5.Lcd.println("RTC TEST");
 
  TimeStruct.Hours   = 18;
  TimeStruct.Minutes = 56;
  TimeStruct.Seconds = 10;
  M5.Rtc.SetTime(&TimeStruct);
}

void loop() {
  M5.Rtc.GetTime(&TimeStruct);
  M5.Lcd.setCursor(0, 15);
  M5.Lcd.printf("Time: %02d : %02d : %02d/n",TimeStruct.Hours, TimeStruct.Minutes, TimeStruct.Seconds);
  delay(500);
}

SetDate()

Description:

Sets the date of a structure variable

Syntax:

void SetDate(RTC_TimeTypeDef* RTC_DateStruct)

Example:


#include <M5StickC.h>

RTC_TimeTypeDef TimeStruct;
RTC_DateTypeDef DateStruct;
void setup() {
  M5.begin();

  DateStruct.WeekDay = 3;
  DateStruct.Month = 3;
  DateStruct.Date = 22;
  DateStruct.Year = 2019;
  M5.Rtc.SetDate(&DateStruct);
}
void loop(){};

GetDate()

Description:

Gets the date from a structure variable

Syntax:

void GetDate(RTC_TimeTypeDef* RTC_DateStruct)

Example:

#include <M5StickC.h>

RTC_DateTypeDef DateStruct;
void setup() {
  M5.begin();
  M5.Lcd.setRotation(3);
  M5.Lcd.fillScreen(BLACK);
 
  M5.Lcd.setTextSize(1);
  M5.Lcd.setCursor(40, 0, 2);
  M5.Lcd.println("RTC TEST");
 
  DateStruct.WeekDay = 3;
  DateStruct.Month = 3;
  DateStruct.Date = 22;
  DateStruct.Year = 2019;
  M5.Rtc.SetDate(&DateStruct);
}

void loop() {
  M5.Rtc.GetDate(&DateStruct);
  M5.Lcd.setCursor(0, 15);
  M5.Lcd.printf("Date:%04d-%02d-%02d/n",DateStruct.Year, DateStruct.Month,DateStruct.Date);
  M5.Lcd.printf("Week:%d/n",DateStruct.WeekDay);
  delay(500);
}
On This Page