正在学习用温湿度传感器将温湿度显示在LCD12864上。代码执行过程中,温度能显示正常,可湿度总是显示为0。 
 
若将
			
			
			- <span style="background-color: rgb(247, 247, 247);">if(millis() - tepTimer > 500){</span>
 
  复制代码 用delay(500);方法代替,则温湿度都能显示正常。请问这是怎么回事啊?不科学啊!!! 
 
 
程序代码如下: 
 
- #include <dht11.h>
 - #include <LCD12864RSPI.h>
 - #define AR_SIZE( a ) sizeof( a ) / sizeof( a[0] )
 - 
 - unsigned long tepTimer;
 - unsigned char tempTitle[] = {0xCE,0xC2,0xB6,0xC8};//温度
 - unsigned char humiTitle[] = {0xCA,0xAA,0xB6,0xC8};//湿度
 - unsigned char line11[] = ":";
 - dht11 DHT;
 - 
 - void setup(){
 -   LCDA.initDriverPin(2,7,10);
 -   LCDA.Initialise();
 -   delay(100);
 - }
 - 
 - void loop(){
 -   int chk = DHT.read(4);
 -   int tempdata;
 -   int humidata;
 -   tempdata = DHT.temperature;
 -   humidata = DHT.humidity;
 - 
 -   if(millis() - tepTimer > 500){
 -     tepTimer = millis();
 -  
 -     LCDA.CLEAR();
 -     LCDA.DisplayString(0,0,tempTitle,AR_SIZE(tempTitle));
 -     LCDA.DisplayString(0,2,line11,AR_SIZE(line11));
 -     shownum(tempdata,0,3,2,0);
 -     LCDA.DisplayString(1,0,humiTitle,AR_SIZE(humiTitle));
 -     LCDA.DisplayString(1,2,line11,AR_SIZE(line11));
 -     shownum(humidata,1,3,2,0);
 -   }
 - }
 - 
 - void shownum(long num, int x, int y, int zlen, int xlen){
 -   char str[zlen];
 -   dtostrf(num,zlen,xlen,str);
 -   LCDA.DisplayString(x,y,(unsigned char *)str,AR_SIZE(str));
 - }
 
  复制代码
  
 
 
 
 
 |