码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 【ESP8266+TM1650时钟数码管+DS3231模块】制作网络时钟


    【ESP8266+TM1650时钟数码管+DS3231模块】制作网络时钟

      • 所需元器件
      • 接线方式
      • 代码

    所需元器件

    • ESP8266 NodeMCU——开发板
    • TM1650时钟数码管——显示时钟
    • DS3231模块——网络对时

    接线方式

    • TM1650
      SCL—>D1
      SDA—>D2
    • DS3231
      SCL—>D1
      SDA—>D2

    代码

    #include 
    #include 
    #include 
    #include 
    #include 
    #include   // not used here, but needed to prevent a RTClib compile error
    #include 
    #include 
    
    
    const char *ssid = "***";
    const char *password = "***";
    
    
    DS3231 RTC;
    TM1650 d;
    UnixTime stamp(8);  // 定义东八区时间
    
    
    WiFiUDP ntpUDP;
    // NTPClient timeClient(ntpUDP, "cn.ntp.org.cn", 28800);
    NTPClient timeClient(ntpUDP, "cn.ntp.org.cn");
    
    
    int h, m, s = 0;
    int ii = 0;
    
    String intToStr(int x) {
      if (x < 10) {
        return "0" + String(x);
      }
      return String(x);
    }
    
    void setup() {
      Serial.begin(74880);
      // Start the I2C interface
      Wire.begin();
      d.init();
      d.displayOn();
      d.setBrightnessGradually(5);
      RTC.begin();
      WiFi.begin(ssid, password);
      while (WiFi.status() != WL_CONNECTED) {  // 连接wifi
        ii++;
        Serial.print(".");
        if (ii % 2 == 0) {
          d.setDot(1, true);
        } else {
          d.setDot(1, false);
        }
        delay(500);
      }
      timeClient.begin();
      d.displayString("8888");
    }
    
    void loop() {
      // 0点更新时间
      if (h + m + s == 0) {
        timeClient.update();
        Serial.println("开始同步NTP时间");
        stamp.getDateTime(timeClient.getEpochTime());
        RTC.adjust(DateTime(stamp.year, stamp.month, stamp.day, stamp.hour, timeClient.getMinutes(), timeClient.getSeconds()));
        Serial.println("同步NTP时间完成");
      }
      // 以下获取RTC时间
      DateTime now = RTC.now();
      h = now.hour();
      m = now.minute();
      s = now.second();
      // 以下格式化HH:MM并显示
      String hhmm = intToStr(h) + intToStr(m);
      char charBuf[10];
      hhmm.toCharArray(charBuf, 10);
      d.displayString(charBuf);
      // 以下显示秒的跳动
      d.setDot(1, true);
      delay(500);
      d.setDot(1, false);
      delay(500);
    }
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84

    时钟效果

  • 相关阅读:
    无线蓝牙耳机哪款性价比高?蓝牙耳机性价比排行
    创建WCF服务
    jupyter报错解决方案 : 无法将“jupyter”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
    C/C++中递归的定义和调用(如何使用递归)
    Mysql 入门篇之二进制安装
    MATLAB算法实战应用案例精讲-【数模应用】随机梯度下降法(SGD)(附Python、R语言、MATLAB和C++代码)
    java练习项目 拼图游戏
    2023年中国新能源汽车电动助力转向系统行业现状分析:随着新能源汽车的发展,产品渗透率的提升[图]
    不懂并发编程原理?面试发怵?别慌,一步一步跟着大佬吃透并发!
    索引失效问题
  • 原文地址:https://blog.csdn.net/sz793919425/article/details/132980890
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号