TA的每日心情 | 奋斗 2019-10-1 12:54 |
---|
签到天数: 313 天 连续签到: 1 天 [LV.8]以坛为家I
|
下面介绍使用Arduino UNO、LCD1602、DS1307制作带日历星期的数字时钟
硬件连接:
DS1307模块的SDA SCL连接Arduino UNO数字输入输出上面一排的SDA SCL,DS1307的VCC GND连接Arduino UNO的ICSP的VCC GND
ICSP排针排列如下
LCD1602的VCC GND SDA SCL连接到Arduino UNO的5V GND A4 A5
连接好之后上电,打开Arduino IDE,打开项目--加载库--管理库,搜索安装rtllib库
如果之前没有安装过LiquidCrystal_I2C库还需要安装这个,安装完成后新建sketch,输入下面代码
#include <Wire.h>#include <RTClib.h>#include <LiquidCrystal_I2C.h>LiquidCrystal_I2C lcd(0x3F,16,2);RTC_DS1307 RTC;char daysOfTheWeek[7][12] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};void setup () { Serial.begin(9600); lcd.init(); lcd.backlight(); Wire.begin(); RTC.begin(); 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.print(' '); Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); Serial.println(); lcd.setCursor(0,0); lcd.print(now.year(), DEC); lcd.print('-'); lcd.print(now.month(), DEC); lcd.print('-'); lcd.print(now.day(), DEC); lcd.print(' '); lcd.print(daysOfTheWeek[now.dayOfTheWeek()]); lcd.setCursor(0,1); lcd.print(now.hour(), DEC); lcd.print(':'); lcd.print(now.minute(), DEC); lcd.print(':'); lcd.print(now.second(), DEC); lcd.print(' '); delay(1000);}
上传后效果如下
|
|