|
|
/*
电路连接
1602lcd :
VSS------->GND
VDD-------->+5V
VO-------->电位器------>GND
RS-------->PIN12
RW-------->CND
E-------->PIN11
D4-------->PIN5
D5-------->PIN4
D6-------->PIN3
D7-------->PIN2
A---------->+5V
K---------->GND
DHT11 数字温湿度:
VDD-------->+5V
DTE-------->PIN8
GND------->GND
实现代码
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
#include <dht11.h>
#define DHT11PIN 8
dht11 DHT11;
char logtxt[] = "Time";
char *sec[60] = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"};
void setup() {
pinMode(DHT11PIN,OUTPUT);
lcd.begin(16, 2);
}
void loop (void)
{
int chk = DHT11.read(DHT11PIN);
lcd.setCursor(0, 0);
lcd.print("Tep:");
lcd.print((float)DHT11.temperature, 0);
lcd.print("C ");
lcd.print("Hum:");
lcd.print((float)DHT11.humidity, 0);
lcd.print("%");
delay(200);
for (int index = 0, minindex = 59, hourindex = 12; index < 60; index++) //这里来设定现在时间,目前设定为12:59:00
{
lcd.setCursor(1, 1);
lcd.print(logtxt);
lcd.print(":");
lcd.print(sec[hourindex]);
lcd.print(":");//显示:
lcd.print(sec[minindex]);
lcd.print(":");
lcd.print(sec[index]);
delay(950);
if (index == 59)
{
index = -1;
minindex++;
if (minindex == 60)
{
minindex = 0;
hourindex++;
if (hourindex == 24)
{
hourindex = 0;
}
}
}
}
} |
|