m5stack / M5Unit-RTC

MIT License
2 stars 1 forks source link

This runs successfully on CoreS3 but when I add some code it return wrong time #2

Closed cohen-sydney closed 3 months ago

cohen-sydney commented 7 months ago

This code as is run on the M5CaoreS3 well. but if I add

include

M5.Begin();

the time out put is zeros. Any ideas why??

pandiannano commented 3 months ago

Try this code:

include "M5CoreS3.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 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); }

cohen-sydney commented 3 months ago

thanks