极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 10447|回复: 0

tft 温湿度计

[复制链接]
发表于 2015-4-3 11:25:40 | 显示全部楼层 |阅读模式
#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 rst  8
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// char array to print to the screen
char HumsensorPrintout[10];
char TmpsensorPrintout[10];
//char string1[10];//温度值字符串变量
//char string2[10];//湿度值字符串变量
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() {
  int  chk1 = (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,看了窜口显示正常,我想应该是数据类型转换出了问题,但是又不知道怎么改。昨晚搞通宵都没有搞好,路过的帮看看,感谢不尽!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-17 17:05 , Processed in 0.092471 second(s), 17 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表