|
在时间是个位的时候会有显示bug的情况
#include <DHT.h>
#include <DHT_U.h>
#include <LiquidCrystal.h>
#include <ThreeWire.h>
#include <RtcDS1302.h>
#include <SPI.h>
#include <SD.h>
#define DHTTYPE DHT11
#define DHTPIN 40
#define DBS1302CLK 25
#define DBS1302DAT 26
#define DBS1302RST 27
float Temp,RH,RTemp;
String WriteData;
byte CelsiusDat[8] =
{
B01100,
B10010,
B10010,
B01100,
B00000,
B00000,
B00000,
B00000
};
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
DHT dht1(DHTPIN,DHTTYPE);
ThreeWire DBS1302(DBS1302DAT,DBS1302CLK,DBS1302RST);
RtcDS1302<ThreeWire> Rtc(DBS1302);
File Data;
void setup()
{
delay(500);
Serial.begin(115200);
lcd.createChar(1,CelsiusDat);
lcd.begin(16,2);
lcd.setCursor(9,1);
lcd.print("bySheng");
lcd.setCursor(5,0);
lcd.print('%');
lcd.setCursor(14,0);
lcd.write(1);
lcd.setCursor(15,0);
lcd.print('C');
dht1.begin();
SD.begin(4);
Data = SD.open("Data.txt",FILE_WRITE);
Rtc.Begin();
}
void loop()
{
delay(80);
RtcDateTime now = Rtc.GetDateTime();
RH = dht1.readHumidity();
Temp = dht1.readTemperature();
RTemp = dht1.computeHeatIndex(Temp,RH,false);
Data = SD.open("Data.txt",FILE_WRITE);
delay(200);
lcd.setCursor(0,0);
lcd.print(RH);
lcd.setCursor(9,0);
lcd.print(Temp);
lcd.setCursor(0,1);
lcd.print(now.Hour());
lcd.setCursor(2,1);
lcd.print(':');
lcd.setCursor(4,1);
lcd.print(now.Minute());
lcd.setCursor(5,1);
lcd.print(':');
lcd.setCursor(6,1);
lcd.print(now.Second());
Data.print(now.Year());
Data.print('/');
Data.print(now.Month());
Data.print('/');
Data.print(now.Day());
Data.print(' ');
Data.print(now.Hour());
Data.print(':');
Data.print(now.Minute());
Data.print(':');
Data.print(now.Second());
Data.print(',');
Data.print(Temp);
Data.print(',');
Data.print(RH);
Data.print(',');
Data.println(RTemp);
Data.close();
}
|
|