当前位置:   article > 正文

ESP32(8):RTC时钟_esp32cam设置rtc时间

esp32cam设置rtc时间

一、ESP32Cam引脚图

二、ArduinoIDE程序编写

ESP32Time.h该文件需要进行安装

public.h

  1. #ifndef _public_H
  2. #define _public_H
  3. #include "Arduino.h"
  4. //类型重定义
  5. typedef unsigned char u8;
  6. typedef unsigned int u16;
  7. typedef unsigned long u32;
  8. #endif

main.c

  1. #include "public.h"
  2. #include <ESP32Time.h>
  3. ESP32Time rtc(3600); // offset in seconds GMT+1
  4. void setup(){
  5. Serial.begin(115200);
  6. rtc.setTime(30, 24, 15, 17, 9, 2022);//2022917152430
  7. }
  8. void loop(){
  9. // Serial.println(rtc.getTime()); // (String) 15:24:38
  10. // Serial.println(rtc.getDate()); // (String) Sun, Jan 17 2021
  11. // Serial.println(rtc.getDate(true)); // (String) Sunday, January 17 2021
  12. // Serial.println(rtc.getDateTime()); // (String) Sun, Jan 17 2021 15:24:38
  13. // Serial.println(rtc.getDateTime(true)); // (String) Sunday, January 17 2021 15:24:38
  14. // Serial.println(rtc.getTimeDate()); // (String) 15:24:38 Sun, Jan 17 2021
  15. // Serial.println(rtc.getTimeDate(true)); // (String) 15:24:38 Sunday, January 17 2021
  16. //
  17. // Serial.println(rtc.getMicros()); // (long) 723546
  18. // Serial.println(rtc.getMillis()); // (long) 723
  19. // Serial.println(rtc.getEpoch()); // (long) 1609459200
  20. // Serial.println(rtc.getSecond()); // (int) 38 (0-59)
  21. // Serial.println(rtc.getMinute()); // (int) 24 (0-59)
  22. // Serial.println(rtc.getHour()); // (int) 3 (0-12)
  23. // Serial.println(rtc.getHour(true)); // (int) 15 (0-23)
  24. // Serial.println(rtc.getAmPm()); // (String) pm
  25. // Serial.println(rtc.getAmPm(true)); // (String) PM
  26. // Serial.println(rtc.getDay()); // (int) 17 (1-31)
  27. // Serial.println(rtc.getDayofWeek()); // (int) 0 (0-6)
  28. // Serial.println(rtc.getDayofYear()); // (int) 16 (0-365)
  29. // Serial.println(rtc.getMonth()); // (int) 0 (0-11)
  30. // Serial.println(rtc.getYear()); // (int) 2021
  31. // Serial.println(rtc.getLocalEpoch()); // (long) 1609459200 epoch without offset
  32. Serial.println(rtc.getTime("%A, %B %d %Y %H:%M:%S")); // (String) returns time with specified format
  33. // formating options http://www.cplusplus.com/reference/ctime/strftime/
  34. delay(1000);
  35. }

最后就可以通过串口查看时间信息。

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号