最近發現自己沒有個小鐘表起床看時間不方便于是就做了一個
成品!
198951865741902697.jpg (339.25 KB, 下載次數: 103)
下載附件
2018-1-17 20:37 上傳
材料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)
2018-1-17 20:43 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|