mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
This commit is contained in:
parent
ffac2f15b7
commit
ce05c3536c
2
DHT.cpp
2
DHT.cpp
@ -46,7 +46,6 @@ float DHT::readTemperature(bool S) {
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Serial.print("Read fail");
|
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +69,6 @@ float DHT::readHumidity(void) {
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Serial.print("Read fail");
|
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,25 +32,26 @@ void loop() {
|
|||||||
float t = dht.readTemperature();
|
float t = dht.readTemperature();
|
||||||
// Read temperature as Fahrenheit
|
// Read temperature as Fahrenheit
|
||||||
float f = dht.readTemperature(true);
|
float f = dht.readTemperature(true);
|
||||||
|
|
||||||
|
// Check if any reads failed and exit early (to try again).
|
||||||
|
if (isnan(h) || isnan(t) || isnan(f)) {
|
||||||
|
Serial.println("Failed to read from DHT sensor!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute heat index
|
// Compute heat index
|
||||||
// Must send in temp in Fahrenheit!
|
// Must send in temp in Fahrenheit!
|
||||||
float hi = dht.computeHeatIndex(f, h);
|
float hi = dht.computeHeatIndex(f, h);
|
||||||
|
|
||||||
// check if returns are valid, if they are NaN (not a number) then something went wrong!
|
Serial.print("Humidity: ");
|
||||||
if (isnan(t) || isnan(h)) {
|
Serial.print(h);
|
||||||
Serial.println("Failed to read from DHT");
|
Serial.print(" %\t");
|
||||||
} else {
|
Serial.print("Temperature: ");
|
||||||
Serial.print("Humidity: ");
|
Serial.print(t);
|
||||||
Serial.print(h);
|
Serial.print(" *C ");
|
||||||
Serial.print(" %\t");
|
Serial.print(f);
|
||||||
Serial.print("Temperature: ");
|
Serial.print(" *F\t");
|
||||||
Serial.print(t);
|
Serial.print("Heat index: ");
|
||||||
Serial.print(" *C ");
|
Serial.print(hi);
|
||||||
Serial.print(f);
|
Serial.println(" *F");
|
||||||
Serial.print(" *F\t");
|
|
||||||
Serial.print("Heat index: ");
|
|
||||||
Serial.print(hi);
|
|
||||||
Serial.println(" *F");
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user