Arduino时钟显示

前言

Arduino 有个很强大的开源的库 u8g2 ,它支持了现在绝大多数的OLED屏幕,至于它的基本用法可以参考我的另一篇笔记,当然这只是我自己的学习笔记写的不是太好,我在文章里贴了官方参考链接可以感兴趣可以去看看。当然,你也可以参考这个博主的单片机菜鸟哥

OLED_SH1106

sh1106是一款1.3寸大小的OLED屏幕,一般有I2C接口和SPI接口,可以将其连接到Arduino Board 的硬件I2C或SPI接口,也可以用软件模拟的方式接到数字I/O口

DS1307时钟模块

硬件介绍我这里就略过了
引脚连接:
SDA------>Arduino SDA
SCL------>Arduino SCL
VCC------>Arduino 5V
GND----->Arduino GND
我使用的是,Arduino的 RTClib 库,可以自己下载,首先我们来看看它的示例程序

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include "RTClib.h"

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {
   "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
   
  Serial.begin(57600);

#ifndef ESP8266
  while (!Serial); // wait for serial port to connect. Needed for native USB
#endif

  if (! rtc.begin()) {
   
    Serial.println("Couldn't find RTC");
    Serial.flush();
    abort();
  }

  if (! rtc.isrunning()) {
   
    Serial.println("RTC is NOT running, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }

  // When time needs to be re-set on a previously configured device, the
  // following line sets the RTC to the date & time this sketch was compiled
  // rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // January 21, 2014 at 3am you would call:
  // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}

void loop () {
   
    DateTime now = rtc.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值