Skip to content

Commit 57fe95c

Browse files
committed
split off the DHT11 conversion, corrected the algorithm for temperatures below 0 degrees celsius.
1 parent d6488c1 commit 57fe95c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

DHT.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ float DHT::readTemperature(bool S, bool force) {
3939
if (read(force)) {
4040
switch (_type) {
4141
case DHT11:
42+
f = data[2];
43+
if (data[3] & 0x80) {
44+
f *= -1 -f ;
45+
}
46+
f += (data[3] & 0x0f) * 0.1;
47+
if(S) {
48+
f = convertCtoF(f);
49+
}
50+
break;
4251
case DHT12:
4352
f = data[2];
4453
f += (data[3] & 0x0f) * 0.1;

0 commit comments

Comments
 (0)