1.安装环境
首选项修改:

https://dl.espressif.com/dl/package_esp32_index.json

2.开发板

安装esp32

3.安装m5stick 库文件

4.选择串口与程序
#include <M5StickC.h>
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
void setup() {
// put your setup code here, to run once:
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");
RTC_TimeTypeDef TimeStruct;
TimeStruct.Hours = 15;
TimeStruct.Minutes = 40;
TimeStruct.Seconds = 33;
M5.Rtc.SetTime(&TimeStruct);
RTC_DateTypeDef DateStruct;
DateStruct.WeekDay = 2;
DateStruct.Month = 4;
DateStruct.Date = 11;
DateStruct.Year = 2020;
M5.Rtc.SetData(&DateStruct);
}
void loop() {
// put your main code here, to run repeatedly:
M5.Rtc.GetTime(&RTC_TimeStruct);
M5.Rtc.GetData(&RTC_DateStruct);
M5.Lcd.setCursor(0, 15);
M5.Lcd.printf("Data: %04d-%02d-%02d\n",RTC_DateStruct.Year, RTC_DateStruct.Month,RTC_DateStruct.Date);
M5.Lcd.printf("Week: %d\n",RTC_DateStruct.WeekDay);
M5.Lcd.printf("Time: %02d : %02d : %02d\n",RTC_TimeStruct.Hours, RTC_TimeStruct.Minutes, RTC_TimeStruct.Seconds);
delay(500);
}

网友评论