最近发现自己没有个小钟表起床看时间不方便于是就做了一个
成品!
材料arduino
ds1302
1602 (有条件的可以使I2c)
dht11
电线若干
接线顺序
1602---12 ,11 ,7 ,6 ,5 ,4
ds1302 ce--2
Io--3
sclk--9dht11----8
使用3个库LiquidCrystal.h DS1302.h dht11.h
直接上原码,没有按键调时,和串口功能,以后改进
- #include <LiquidCrystal.h>
- #include <DS1302.h>
- #include <dht11.h> // DHT11 传感器程序库
- // Init the DS1302
- DS1302 rtc(2, 3, 9);
- // Init the LCD
- LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
- void setup()
- {
- // Set the clock to run-mode, and disable the write protection
- rtc.halt(false);
- rtc.writeProtect(false);
- // Setup LCD to 16x2 characters
- lcd.begin(16, 2);
- // The following lines can be commented out to use the values already stored in the DS1302
- rtc.setDOW(TUESDAY); // Set Day-of-Week to FRIDAY
- rtc.setTime(22,05, 0); // Set the time to 12:00:00 (24hr format)
- rtc.setDate(24,10,2017); // Set the date to August 6th, 2010
- }
- void loop(){
- // Display time centered on the upper line
- lcd.setCursor(1, 0);
- lcd.print(rtc.getTimeStr());
- // Display abbreviated Day-of-Week in the lower left corner
- lcd.setCursor(12, 0);
- lcd.print(rtc.getDOWStr(FORMAT_SHORT));
- // Display date in the lower right corner
- lcd.setCursor(6, 1);
- lcd.print(rtc.getDateStr());
- // Wait one second before repeating :)
- delay (1000);
- dht11 DHT11; // 温湿度传感器程序对象
- const byte dataPin = 8;
- int chk = DHT11.read(dataPin);
- if (chk == 0)
- lcd.setCursor(0, 1); // 显示温度
- lcd.print((float)DHT11.temperature, 1);
- lcd.print((char) 0xDF);
- }
复制代码
全部资料51hei下载地址:
数字钟.zip
(94.95 KB, 下载次数: 106)
|