[mw_shl_code=c,true]#include <UTFT.h>
#include <dht11.h>
dht11 DHT11;
#define DHT11PIN 4
UTFT myGLCD(YYROBOT_TFT144,A2,A1,A5,A4,A3); // Remember to change the model parameter to suit your display module!
//YYROBOT_TFT144 屏幕型号,不用修改
//SDA----A2
//SCL----A1
//CS-----A5
//RST----A4
//RS----A3
//LED---A0 UTFT库里面设定的,如果需要修改需要修改库文件
extern uint8_t SmallFont[];//原始文件在库文件的DefaultFonts.c中
extern uint8_t BigFont[];//原始文件在库文件的DefaultFonts.c中
extern uint8_t SevenSegNumFont[];//原始文件在库文件的DefaultFonts.c中
void setup()
{ Serial.begin(9600);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
// Setup the LCD
myGLCD.InitLCD();//初始化液晶
myGLCD.InitLCD();//初始化两次有利于系统稳定
myGLCD.setFont(SmallFont);//设置字体为SmallFont格式
myGLCD.fillScr(255,0,0);//填充RED
delay (50);
myGLCD.fillScr(0,255,0);//填充GREEN
delay (50);
myGLCD.fillScr(0,0,255);//填充BLUE
delay (50);
myGLCD.setColor(255, 255, 255);
int chk = DHT11.read(DHT11PIN);
if(chk==DHTLIB_OK)
{ switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
myGLCD.print("System Ready! ", CENTER, 20);
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
myGLCD.print("error! ", CENTER, 20);
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
myGLCD.print("error! ", CENTER, 20);
break;
default:
Serial.println("Unknown error");
myGLCD.print("Unknown! ", CENTER, 20);
break; }
delay(1000);
}
myGLCD.clrScr(); //清屏
}
void loop()
{ int chk = DHT11.read(DHT11PIN);
myGLCD.setColor(255, 255, 255);//设置字体颜色
myGLCD.setBackColor(255, 100,0);//设置背景颜色
myGLCD.setFont(SmallFont);//设置字体为SmallFont格式(8*12字符)
myGLCD.print("Environmental ", CENTER, 10);
myGLCD.print("HuangXin&Phineas ", CENTER, 20);
myGLCD.setFont(BigFont); //设置大字体BigFont(16*16字符)
myGLCD.setBackColor(255, 0,100);//设置背景颜色
myGLCD.print("Humi:", LEFT, 40); //打印YYROBOT,靠左显示,显示在20行
int i= (int)DHT11.humidity;
myGLCD.printNumI(i, 0, 60, 4, '0');
myGLCD.print("Temp:", LEFT, 80);
int j= (int)DHT11.temperature;
myGLCD.printNumI(j, 0, 100, 4, '0');
delay (1000);
// while(1);
}
double Fahrenheit(double celsius)
{
return 1.8 * celsius + 32;
} //摄氏温度度转化为华氏温度
double Kelvin(double celsius)
{
return celsius + 273.15;
} //摄氏温度转化为开氏温度
// 露点(点在此温度时,空气饱和并产生露珠)
// 参考:
http://wahiduddin.net/calc/density_algorithms.htm
double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
// 快速计算露点,速度是5倍dewPoint()
// 参考:
http://en.wikipedia.org/wiki/Dew_point
double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}[/mw_shl_code]