arduino学习笔记之Tiny RTC 12C 时钟模块

网友投稿 2018-11-28 11:34

之前的学习笔记中有一篇“arduino学习笔记之DS1307 RTC时钟芯片与DS18B20数字温度传感器实验”现在看来那个文章稍微有点“旧了”今天更新一个新库使用更方便

https://cdn.china-scratch.com/timg/181130/1134313294-0.jpg

https://cdn.china-scratch.com/timg/181130/1134312029-1.jpg以下为控制代码: 
【库文件:RTClib】 

#include

#include

RTC_DS1307 RTC;

void setup () {

    Serial.begin(9600);

    Wire.begin();

    RTC.begin();

    if (! RTC.isrunning()) {

        Serial.println("RTC is NOT running!");

    RTC.adjust(DateTime(__DATE__, __TIME__));

  }

}

void loop () {

    DateTime now = RTC.now(); 

    Serial.print(now.year(), DEC);

    Serial.print('/');

    Serial.print(now.month(), DEC);

    Serial.print('/');

    Serial.print(now.day(), DEC);

    Serial.print(' ');

    Serial.print(now.hour(), DEC);

    Serial.print(':');

    Serial.print(now.minute(), DEC);

    Serial.print(':');

    Serial.print(now.second(), DEC);

    Serial.println(); 

    delay(1000);

}

--end--

声明:本文章由网友投稿作为教育分享用途,如有侵权原作者可通过邮件及时和我们联系删除:freemanzk@qq.com