献丑 献丑
#include <Wire.h>
#include <LiquidCrystal.h>
#include <DS3231.h>
#include "dht.h"
// Arduino的SCL引脚位于模拟端口5,SDA引脚位于模拟端口4。
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
DS3231 Clock;
bool Century=false;
bool PM=false;
dht DHT;
#define DHT11_PIN 6
byte year, month, date, DoW, hour, Minute, Second;
void setup() {
// set up the LCD's number of columns and rows:
Wire.begin();
lcd.begin(16, 2);
// Turn on the blinking cursor:
lcd.blink();
}
void loop()
{
hour=Clock.getHour(Century, PM);
Minute=Clock.getMinute();
Second=Clock.getSecond();
lcd.home();
lcd.setCursor(0, 0);
// 以下是在每天的22:22做的时间修正
// if (hour==22 && Second==22 && Minute== 22) { Clock.setSecond(Second+1-1);}
if (hour<10) lcd.print(" ");
lcd.print(hour);
lcd.print(":");
if (Minute<10) lcd.print(" ");
lcd.print(Minute);
lcd.print(":");
if (Second<10) lcd.print(" ");
lcd.print(Second);
lcd.setCursor(10, 0);
lcd.print(" T=");
lcd.print(Clock.getTemperature(), 1);
lcd.print(" ");
lcd.setCursor(15, 0);
if ( Second<30 )
{
lcd.setCursor(0, 1);
lcd.print(Clock.getYear());
lcd.print("-");
lcd.print(Clock.getMonth(Century));
lcd.print("-");
lcd.print(Clock.getDate());
lcd.print(" WeEk :");//显示周几。
lcd.print(Clock.getDoW());
}
else
{
lcd.setCursor(0, 1);
lcd.print("HUMIDY=");//显示湿度。
lcd.print(DHT.humidity, 0);
lcd.setCursor(10, 1);
lcd.print(" T=");
lcd.print( DHT.temperature,1);
}
delay(500);
}
|