#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT_NEW.h"
LiquidCrystal_I2C _lcd1(0x27, 16, 2);
int _dispTempLength1=0;
boolean _isNeedClearDisp1;
DHT _dht1;
float _gtv1;
float _gtv2;
int _disp1oldLength = 0;
unsigned long _dht1LRT = 0UL;
unsigned long _dht1Tti = 0UL;
int _disp3oldLength = 0;
void setup()
{
Wire.begin();
delay(10);
_lcd1.init();
_lcd1.backlight();
_dht1.setup(2);
_dht1LRT = millis();
_dht1Tti = millis();
}
void loop()
{
if (_isNeedClearDisp1) {_lcd1.clear(); _isNeedClearDisp1= 0;}
//Плата:1
if(_isTimer(_dht1Tti, 1000)) {
if(_isTimer(_dht1LRT,( _dht1.getMinimumSamplingPeriod()))) {
_dht1.readSensor();
_dht1LRT = millis();
_dht1Tti = millis();
}
}
_gtv1 = _dht1.humidity;
_gtv2 = _dht1.temperature;
if (1) {
_dispTempLength1 = ((((String("T ~ ")) + ((String((int(_gtv2)), DEC))) + (String(" C"))))).length();
if (_disp3oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp3oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 0);
_lcd1.print((((String("T ~ ")) + ((String((int(_gtv2)), DEC))) + (String(" C")))));
} else {
if (_disp3oldLength > 0) {_isNeedClearDisp1 = 1; _disp3oldLength = 0;}
}
if (1) {
_dispTempLength1 = ((((String("H ~ ")) + ((String((int(_gtv1)), DEC))) + (String(" %"))))).length();
if (_disp1oldLength > _dispTempLength1) {_isNeedClearDisp1 = 1;}
_disp1oldLength = _dispTempLength1;
_lcd1.setCursor(int((16 - _dispTempLength1)/2), 1);
_lcd1.print((((String("H ~ ")) + ((String((int(_gtv1)), DEC))) + (String(" %")))));
} else {
if (_disp1oldLength > 0) {_isNeedClearDisp1 = 1; _disp1oldLength = 0;}
}
}
bool _isTimer(unsigned long startTime, unsigned long period )
{
unsigned long currentTime;
currentTime = millis();
if (currentTime>= startTime) {return (currentTime>=(startTime + period));} else {return (currentTime >=(4294967295-startTime+period));}
}
вот такой код.
вот такая прога.
Попробовал датчик ds18b20 - все нормально показывает.