初始化提交
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2021 by M5Stack
|
||||
* Equipped with M5Core2 sample source code
|
||||
* 配套 M5Core2 示例源代码
|
||||
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
|
||||
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
|
||||
*
|
||||
* describe: RTC--实时时钟示例
|
||||
* date: 2022/1/9
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <M5Core2.h>
|
||||
|
||||
RTC_TimeTypeDef RTCtime;
|
||||
RTC_DateTypeDef RTCDate;
|
||||
|
||||
char timeStrbuff[64];
|
||||
|
||||
void flushTime() {
|
||||
M5.Rtc.GetTime(&RTCtime); // Gets the time in the real-time clock.
|
||||
// 获取实时时钟内的时间
|
||||
M5.Rtc.GetDate(&RTCDate);
|
||||
sprintf(timeStrbuff, "%d/%02d/%02d %02d:%02d:%02d", RTCDate.Year,
|
||||
RTCDate.Month, RTCDate.Date, RTCtime.Hours, RTCtime.Minutes,
|
||||
RTCtime.Seconds);
|
||||
// Stores real-time time and date data
|
||||
// to timeStrbuff.
|
||||
// 将实时时间、日期数据存储至timeStrbuff
|
||||
M5.lcd.setCursor(10, 100);
|
||||
// Move the cursor position to (x,y). 移动光标位置到(x,y)处
|
||||
M5.Lcd.println(timeStrbuff);
|
||||
// Output the contents of. 输出timeStrbuff中的内容
|
||||
}
|
||||
|
||||
void setupTime() {
|
||||
RTCtime.Hours = 16; // Set the time. 设置时间
|
||||
RTCtime.Minutes = 51;
|
||||
RTCtime.Seconds = 20;
|
||||
if (!M5.Rtc.SetTime(&RTCtime)) Serial.println("wrong time set!");
|
||||
// and writes the set time to the real
|
||||
// time clock. 并将设置的时间写入实时时钟
|
||||
RTCDate.Year = 2022; // Set the date. 设置日期
|
||||
RTCDate.Month = 1;
|
||||
RTCDate.Date = 9;
|
||||
if (!M5.Rtc.SetDate(&RTCDate)) Serial.println("wrong date set!");
|
||||
}
|
||||
/* After M5Core2 is started or reset
|
||||
the program in the setUp () function will be run, and this part will only be run
|
||||
once. 在 M5Core2
|
||||
启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
|
||||
void setup() {
|
||||
M5.begin(); // Init M5Core2. 初始化 M5Core2
|
||||
delay(1000);
|
||||
setupTime();
|
||||
M5.Lcd.setTextSize(2); // Set the text size. 设置文本大小
|
||||
}
|
||||
|
||||
/* After the program in setup() runs, it runs the program in loop()
|
||||
The loop() function is an infinite loop in which the program runs repeatedly
|
||||
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
|
||||
loop()函数是一个死循环,其中的程序会不断的重复运行 */
|
||||
void loop() {
|
||||
flushTime();
|
||||
delay(1000);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (c) 2021 by M5Stack
|
||||
* Equipped with M5Core2 sample source code
|
||||
* 配套 M5Core2 示例源代码
|
||||
* Visit the website for more information: https://docs.m5stack.com/en/core/core2
|
||||
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/core2
|
||||
*
|
||||
* describe: RTC--时间管理示例
|
||||
* date: 2021/7/21
|
||||
*******************************************************************************
|
||||
*/
|
||||
#include <M5Core2.h>
|
||||
|
||||
RTC_TimeTypeDef RTCtime;
|
||||
RTC_TimeTypeDef RTCtime_Now;
|
||||
|
||||
char timeStrbuff[64];
|
||||
|
||||
/* After M5Core2 is started or reset
|
||||
the program in the setUp () function will be run, and this part will only be run once.
|
||||
在 M5Core2 启动或者复位后,即会开始执行setup()函数中的程序,该部分只会执行一次。 */
|
||||
void setup(){
|
||||
M5.begin(); //Init M5Core2. 初始化 M5Stack
|
||||
|
||||
RTCtime.Hours = 10; // Set the time. 设置时间
|
||||
RTCtime.Minutes = 30;
|
||||
RTCtime.Seconds = 45;
|
||||
M5.Lcd.setCursor(0,80); // Move the cursor position to (x,y). 移动光标位置到(x,y)处
|
||||
M5.Lcd.println("BtnA: shutdown, use power button to turn back on"); // The screen prints the formatted string and wraps it. 屏幕打印格式化字符串并换行
|
||||
M5.Lcd.println("BtnB: shutdown, wake up after 5 seconds");
|
||||
M5.Lcd.printf("BtnC: shutdown, wake up at RTC Time %d:%d:%d",RTCtime.Hours,RTCtime.Minutes, RTCtime.Seconds);
|
||||
}
|
||||
|
||||
/* After the program in setup() runs, it runs the program in loop()
|
||||
The loop() function is an infinite loop in which the program runs repeatedly
|
||||
在setup()函数中的程序执行完后,会接着执行loop()函数中的程序
|
||||
loop()函数是一个死循环,其中的程序会不断的重复运行 */
|
||||
void loop(){
|
||||
M5.update(); //Read the status of keys A, B, and C. 读取按键 A, B, C 的状态
|
||||
|
||||
if(M5.BtnA.wasPressed()){ //Constantly check the status of keys A, B, and C, if A press..... 不断检测按键A、B、C的状态,如果A按下....
|
||||
M5.shutdown(); //Turn off the power. 关闭电源
|
||||
}else if(M5.BtnB.wasPressed()){
|
||||
M5.shutdown(5); //Turn off the power and wake up again after 5 seconds. 关闭电源,5秒后再次唤醒
|
||||
}else if(M5.BtnC.wasPressed()){
|
||||
M5.shutdown(RTCtime); //Turn off the power and wake up at the specified time. 关闭电源,在指定时间唤醒
|
||||
}
|
||||
|
||||
M5.Lcd.setCursor(0,140);
|
||||
M5.Rtc.GetTime(&RTCtime_Now); //Gets the current time. 获取当前时间
|
||||
sprintf(timeStrbuff,"RTC Time Now is %02d:%02d:%02d", //Stores real-time time data to timeStrbuff. 将实时时间数据存储至timeStrbuff
|
||||
RTCtime_Now.Hours,RTCtime_Now.Minutes,RTCtime_Now.Seconds);
|
||||
M5.Lcd.println(timeStrbuff); //Screen printing output timeStrbuff. 输出timeStrbuff
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user