hgmyaoming 发表于 2015-4-3 11:25:40

tft 温湿度计

#include<dht11.h>
#include <TFT.h>// Arduino LCD library
#include <SPI.h>
#define DHT11PIN 2
dht11 DHT11;
// pin definition for the Uno
#define cs   10
#define dc   9
#define rst8
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// char array to print to the screen
char HumsensorPrintout;
char TmpsensorPrintout;
//char string1;//温度值字符串变量
//char string2;//湿度值字符串变量
void setup() {
pinMode(DHT11PIN,OUTPUT);
// Put this line at the beginning of every sketch that uses the GLCD:
Serial.begin(9600);
TFTscreen.begin();
// clear the screen with a black background
TFTscreen.background(0, 0, 0);
}

void loop() {
intchk1 = (DHT11.read(DHT11PIN));
String chk = String(DHT11.read(DHT11PIN));
// convert the reading to a char array
chk.toCharArray(HumsensorPrintout, 10);
chk.toCharArray(TmpsensorPrintout, 10);
   // write the static text to the screen
// set the font color to white
TFTscreen.stroke(255, 255, 255);
// set the font size
TFTscreen.setTextSize(2);
TFTscreen.text("HUM :\n ", 0, 4);
TFTscreen.text(HumsensorPrintout,20 , 30);
//lcd.print((float)DHT11.temperature, 2);
// lcd.print("C");
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
   TFTscreen.text("TMP : \n", 0, 60);
   TFTscreen.text(TmpsensorPrintout,20 , 90);
Serial.print("Humidity (%): ");
Serial.println(DHT11.humidity);
//Serial.println(HumsensorPrintout);
Serial.print("Temperature (oC): ");
Serial.println(DHT11.temperature);
//Serial.println(TmpsensorPrintout);
delay(2500);
TFTscreen.stroke(0, 0, 0);
TFTscreen.text(HumsensorPrintout,20 ,30);
TFTscreen.text(TmpsensorPrintout,20, 90);

}
运行后,总是显示-2,看了窜口显示正常,我想应该是数据类型转换出了问题,但是又不知道怎么改。昨晚搞通宵都没有搞好,路过的帮看看,感谢不尽!!
页: [1]
查看完整版本: tft 温湿度计