diff --git a/examples/Unit_RTC_M5Atom/Unit_RTC_M5Atom.ino b/examples/Unit_RTC_M5Atom/Unit_RTC_M5Atom.ino new file mode 100644 index 0000000..8373690 --- /dev/null +++ b/examples/Unit_RTC_M5Atom/Unit_RTC_M5Atom.ino @@ -0,0 +1,54 @@ +/* +******************************************************************************* +* Copyright (c) 2022 by M5Stack +* Equipped with Atom-Lite/Matrix sample source code +* 配套 Atom-Lite/Matrix 示例源代码 +* Visit for more information: https://docs.m5stack.com/en/unit/rtc +* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rtc +* +* Product: RTC. 实时时钟 +* Date: 2022/7/29 +******************************************************************************* + Please connect to Port A,The time is displayed on the screen. + 请连接端口A,屏幕上显示时间。 +*/ + +#include "M5Atom.h" +#include "Unit_RTC.h" + +Unit_RTC RTC; + +rtc_time_type RTCtime; +rtc_date_type RTCdate; + +char str_buffer[64]; + +void setup() { + M5.begin(true, false, true); // Init M5Atom. 初始化M5Atom + Serial.print("RTC"); + RTC.begin(); // Example Initialize the RTC clock. 初始化RTC时钟 + RTCtime.Hours = 14; // Set the RTC clock time. 设置RTC时钟时间 + RTCtime.Minutes = 40; + RTCtime.Seconds = 5; + + RTCdate.WeekDay = 4; // Set the RTC clock date. 设置RTC时钟日期 + RTCdate.Month = 7; + RTCdate.Date = 15; + RTCdate.Year = 2021; + + RTC.setTime(&RTCtime); // Example Synchronize the set time to the RTC. + // 将设置的时间同步至RTC + RTC.setDate(&RTCdate); // Synchronize the set date to the RTC. + // 将设置的日期同步至RTC + M5.dis.fillpix(0x00ff00); +} + +void loop() { + RTC.getTime(&RTCtime); // To get the time. 获取时间 + RTC.getDate(&RTCdate); // Get the date. 获取日期 + Serial.printf("RTC Time Now is \n%02d:%02d:%02d\n", RTCtime.Hours, + RTCtime.Minutes, RTCtime.Seconds); + Serial.printf("RTC Date Now is \n%02d:%02d:%02d WeekDay:%02d\n", + RTCdate.Year, RTCdate.Month, RTCdate.Date, RTCdate.WeekDay); + delay(1000); +} diff --git a/examples/Unit_RTC_M5Core/Unit_RTC_M5Core.ino b/examples/Unit_RTC_M5Core/Unit_RTC_M5Core.ino new file mode 100644 index 0000000..1817220 --- /dev/null +++ b/examples/Unit_RTC_M5Core/Unit_RTC_M5Core.ino @@ -0,0 +1,57 @@ +/* +******************************************************************************* +* Copyright (c) 2022 by M5Stack +* Equipped with M5Core sample source code +* 配套 M5Core 示例源代码 +* Visit for more information: https://docs.m5stack.com/en/unit/rtc +* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rtc +* +* Product: RTC. 实时时钟 +* Date: 2022/7/29 +******************************************************************************* + Please connect to Port A,The time is displayed on the screen. + 请连接端口A,屏幕上显示时间。 +*/ + +#include "M5Stack.h" +#include "Unit_RTC.h" + +Unit_RTC RTC; + +rtc_time_type RTCtime; +rtc_date_type RTCdate; + +char str_buffer[64]; + +void setup() { + M5.begin(); // Init M5Stack. 初始化M5Stack + M5.Power.begin(); // Init power 初始化电源模块 + M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2 + M5.Lcd.print(" RTC"); + RTC.begin(); // Example Initialize the RTC clock. 初始化RTC时钟 + RTCtime.Hours = 14; // Set the RTC clock time. 设置RTC时钟时间 + RTCtime.Minutes = 40; + RTCtime.Seconds = 5; + + RTCdate.WeekDay = 4; // Set the RTC clock date. 设置RTC时钟日期 + RTCdate.Month = 7; + RTCdate.Date = 15; + RTCdate.Year = 2021; + + RTC.setTime(&RTCtime); // Example Synchronize the set time to the RTC. + // 将设置的时间同步至RTC + RTC.setDate(&RTCdate); // Synchronize the set date to the RTC. + // 将设置的日期同步至RTC +} + +void loop() { + M5.Lcd.fillRect(0, 20, 320, 140, BLACK); + RTC.getTime(&RTCtime); // To get the time. 获取时间 + RTC.getDate(&RTCdate); // Get the date. 获取日期 + M5.Lcd.setCursor(0, 20); + M5.Lcd.printf("RTC Time Now is \n%02d:%02d:%02d\n", RTCtime.Hours, + RTCtime.Minutes, RTCtime.Seconds); + M5.Lcd.printf("RTC Date Now is \n%02d:%02d:%02d WeekDay:%02d\n", + RTCdate.Year, RTCdate.Month, RTCdate.Date, RTCdate.WeekDay); + delay(1000); +} diff --git a/examples/Unit_RTC_M5Core2/Unit_RTC_M5Core2.ino b/examples/Unit_RTC_M5Core2/Unit_RTC_M5Core2.ino new file mode 100644 index 0000000..5b9e22b --- /dev/null +++ b/examples/Unit_RTC_M5Core2/Unit_RTC_M5Core2.ino @@ -0,0 +1,56 @@ +/* +******************************************************************************* +* Copyright (c) 2021 by M5Stack +* Equipped with M5Core2 sample source code +* 配套 M5Core2 示例源代码 +* Visit for more information: https://docs.m5stack.com/en/unit/rtc +* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rtc +* +* Product: RTC. 实时时钟 +* Date: 2021/8/18 +******************************************************************************* + Please connect to Port A,The time is displayed on the screen. + 请连接端口A,屏幕上显示时间。 +*/ + +#include "M5Core2.h" +#include "M5_BM8563.h" + +BM8563 RTC; + +rtc_time_type RTCtime; +rtc_date_type RTCdate; + +char str_buffer[64]; + +void setup() { + M5.begin(); //Init M5Core2. 初始化M5Core2 + M5.lcd.setTextSize(2); //Set the text size to 2. 设置文字大小为2 + M5.Lcd.print(" RTC"); + RTC.begin(); //Example Initialize the RTC clock. 初始化RTC时钟 + RTCtime.Hours = 14; //Set the RTC clock time. 设置RTC时钟时间 + RTCtime.Minutes = 40; + RTCtime.Seconds = 5; + + RTCdate.WeekDay = 4; //Set the RTC clock date. 设置RTC时钟日期 + RTCdate.Month = 7; + RTCdate.Date = 15; + RTCdate.Year = 2021; + + RTC.setTime( + &RTCtime); //Example Synchronize the set time to the RTC. 将设置的时间同步至RTC + RTC.setDate( + &RTCdate); //Synchronize the set date to the RTC. 将设置的日期同步至RTC +} + +void loop() { + RTC.getTime(&RTCtime); //To get the time. 获取时间 + RTC.getDate(&RTCdate); //Get the date. 获取日期 + M5.Lcd.setCursor(0, 20); + M5.Lcd.printf("RTC Time Now is \n%02d:%02d:%02d\n", RTCtime.Hours, + RTCtime.Minutes, RTCtime.Seconds); + M5.Lcd.printf("RTC Date Now is \n%02d:%02d:%02d WeekDay:%02d\n", RTCdate.Year, + RTCdate.Month, RTCdate.Date, RTCdate.WeekDay); + delay(1000); + M5.Lcd.fillRect(0, 20, 320, 140, BLACK); +} diff --git a/examples/Unit_RTC_M5StickC/Unit_RTC_M5StickC.ino b/examples/Unit_RTC_M5StickC/Unit_RTC_M5StickC.ino new file mode 100644 index 0000000..fc33838 --- /dev/null +++ b/examples/Unit_RTC_M5StickC/Unit_RTC_M5StickC.ino @@ -0,0 +1,56 @@ +/* +******************************************************************************* +* Copyright (c) 2021 by M5Stack +* Equipped with M5StickC sample source code +* 配套 M5StickC 示例源代码 +* Visit for more information: https://docs.m5stack.com/en/unit/rtc +* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rtc +* +* Product: RTC. 实时时钟 +* Date: 2022/7/29 +******************************************************************************* + Please connect to Port,The time is displayed on the screen. + 请连接端口,屏幕上显示时间。 +*/ + +#include "M5StickC.h" +#include "Unit_RTC.h" + +Unit_RTC RTC; + +rtc_time_type RTCtime; +rtc_date_type RTCdate; + +char str_buffer[64]; + +void setup() { + M5.begin(); // Init M5StickC. 初始化M5StickC + M5.Lcd.setRotation(3); // Rotating display. 旋转显示屏 + M5.Lcd.print(" RTC"); + RTC.begin(); // Example Initialize the RTC clock. 初始化RTC时钟 + RTCtime.Hours = 14; // Set the RTC clock time. 设置RTC时钟时间 + RTCtime.Minutes = 40; + RTCtime.Seconds = 5; + + RTCdate.WeekDay = 4; // Set the RTC clock date. 设置RTC时钟日期 + RTCdate.Month = 7; + RTCdate.Date = 15; + RTCdate.Year = 2021; + + RTC.setTime(&RTCtime); // Example Synchronize the set time to the RTC. + // 将设置的时间同步至RTC + RTC.setDate(&RTCdate); // Synchronize the set date to the RTC. + // 将设置的日期同步至RTC +} + +void loop() { + RTC.getTime(&RTCtime); // To get the time. 获取时间 + RTC.getDate(&RTCdate); // Get the date. 获取日期 + M5.Lcd.setCursor(0, 20); + M5.Lcd.printf("RTC Time Now is \n%02d:%02d:%02d\n", RTCtime.Hours, + RTCtime.Minutes, RTCtime.Seconds); + M5.Lcd.printf("RTC Date Now is \n%02d:%02d:%02d WeekDay:%02d\n", + RTCdate.Year, RTCdate.Month, RTCdate.Date, RTCdate.WeekDay); + delay(1000); + M5.Lcd.fillRect(0, 20, 320, 140, BLACK); +} diff --git a/examples/Unit_RTC_M5StickCPlus/Unit_RTC_M5StickCPlus.ino b/examples/Unit_RTC_M5StickCPlus/Unit_RTC_M5StickCPlus.ino new file mode 100644 index 0000000..effd998 --- /dev/null +++ b/examples/Unit_RTC_M5StickCPlus/Unit_RTC_M5StickCPlus.ino @@ -0,0 +1,57 @@ +/* +******************************************************************************* +* Copyright (c) 2021 by M5Stack +* Equipped with M5StickCPlus sample source code +* 配套 M5StickCPlus 示例源代码 +* Visit for more information: https://docs.m5stack.com/en/unit/rtc +* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/rtc +* +* Product: RTC. 实时时钟 +* Date: 2022/7/29 +******************************************************************************* + Please connect to Port,The time is displayed on the screen. + 请连接端口,屏幕上显示时间。 +*/ + +#include "M5StickCPlus.h" +#include "Unit_RTC.h" + +Unit_RTC RTC; + +rtc_time_type RTCtime; +rtc_date_type RTCdate; + +char str_buffer[64]; + +void setup() { + M5.begin(); // Init M5StickCPlus. 初始化M5StickCPlus + M5.Lcd.setRotation(3); // Rotating display. 旋转显示屏 + M5.Lcd.setTextSize(2); // Rotating display. 旋转显示屏 + M5.Lcd.print(" RTC"); + RTC.begin(); // Example Initialize the RTC clock. 初始化RTC时钟 + RTCtime.Hours = 14; // Set the RTC clock time. 设置RTC时钟时间 + RTCtime.Minutes = 40; + RTCtime.Seconds = 5; + + RTCdate.WeekDay = 4; // Set the RTC clock date. 设置RTC时钟日期 + RTCdate.Month = 7; + RTCdate.Date = 15; + RTCdate.Year = 2021; + + RTC.setTime(&RTCtime); // Example Synchronize the set time to the RTC. + // 将设置的时间同步至RTC + RTC.setDate(&RTCdate); // Synchronize the set date to the RTC. + // 将设置的日期同步至RTC +} + +void loop() { + RTC.getTime(&RTCtime); // To get the time. 获取时间 + RTC.getDate(&RTCdate); // Get the date. 获取日期 + M5.Lcd.setCursor(0, 20); + M5.Lcd.printf("RTC Time Now is \n%02d:%02d:%02d\n", RTCtime.Hours, + RTCtime.Minutes, RTCtime.Seconds); + M5.Lcd.printf("RTC Date Now is \n%02d:%02d:%02d WeekDay:%02d\n", + RTCdate.Year, RTCdate.Month, RTCdate.Date, RTCdate.WeekDay); + delay(1000); + M5.Lcd.fillRect(0, 20, 320, 140, BLACK); +} diff --git a/library.json b/library.json index 7126325..7fa7046 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "M5Unit-RTC", - "description": "Library for M5Stack Unit RTC", + "description": "Library for M5Stack Unit RTC(SKU:U126)", "keywords": "M5Stack Unit BM8563 RTC", "authors": { "name": "M5Stack", @@ -10,7 +10,7 @@ "type": "git", "url": "https://github.com/m5stack/M5Unit-RTC.git" }, - "version": "0.0.1", + "version": "0.0.2", "frameworks": "arduino", "platforms": "espressif32" } \ No newline at end of file diff --git a/library.properties b/library.properties index 46a2844..0f3e4d6 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Unit-RTC -version=0.0.1 +version=0.0.2 author=M5Stack maintainer=M5Stack sentence=Library for BM8563 RTC diff --git a/src/Unit_RTC.h b/src/Unit_RTC.h index fd062fd..49bd32f 100644 --- a/src/Unit_RTC.h +++ b/src/Unit_RTC.h @@ -3,8 +3,8 @@ * @copyright Copyright (c) 2022 by M5Stack[https://m5stack.com] * * @Links [Unit RTC](https://docs.m5stack.com/en/unit/rtc) - * @version V0.0.1 - * @date 2022-07-15 + * @version V0.0.2 + * @date 2022-07-29 */ #ifndef _Unit_RTC_H__ #define _Unit_RTC_H__