mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
Merge pull request #125 from sijskes/master
fixed incorrect values on DHT11 below 0 degrees celcius
This commit is contained in:
commit
1e752b12ee
15
DHT.cpp
15
DHT.cpp
@ -39,6 +39,15 @@ float DHT::readTemperature(bool S, bool force) {
|
|||||||
if (read(force)) {
|
if (read(force)) {
|
||||||
switch (_type) {
|
switch (_type) {
|
||||||
case DHT11:
|
case DHT11:
|
||||||
|
f = data[2];
|
||||||
|
if (data[3] & 0x80) {
|
||||||
|
f = -1 - f ;
|
||||||
|
}
|
||||||
|
f += (data[3] & 0x0f) * 0.1;
|
||||||
|
if(S) {
|
||||||
|
f = convertCtoF(f);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case DHT12:
|
case DHT12:
|
||||||
f = data[2];
|
f = data[2];
|
||||||
f += (data[3] & 0x0f) * 0.1;
|
f += (data[3] & 0x0f) * 0.1;
|
||||||
@ -155,11 +164,11 @@ bool DHT::read(bool force) {
|
|||||||
pinMode(_pin, OUTPUT);
|
pinMode(_pin, OUTPUT);
|
||||||
digitalWrite(_pin, LOW);
|
digitalWrite(_pin, LOW);
|
||||||
switch(_type) {
|
switch(_type) {
|
||||||
case DHT22:
|
case DHT22:
|
||||||
case DHT21:
|
case DHT21:
|
||||||
delayMicroseconds(1100); // data sheet says "at least 1ms"
|
delayMicroseconds(1100); // data sheet says "at least 1ms"
|
||||||
break;
|
break;
|
||||||
case DHT11:
|
case DHT11:
|
||||||
default:
|
default:
|
||||||
delay(20); //data sheet says at least 18ms, 20ms just to be safe
|
delay(20); //data sheet says at least 18ms, 20ms just to be safe
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user