mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
Added support for Celsius in computeHeatIndex
This commit is contained in:
parent
fcd865b3bc
commit
25942ac8b9
28
DHT.cpp
28
DHT.cpp
@ -20,7 +20,7 @@ void DHT::begin(void) {
|
|||||||
_lastreadtime = 0;
|
_lastreadtime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//boolean S == Scale. True == Farenheit; False == Celcius
|
//boolean S == Scale. True == Fahrenheit; False == Celcius
|
||||||
float DHT::readTemperature(bool S) {
|
float DHT::readTemperature(bool S) {
|
||||||
float f;
|
float f;
|
||||||
|
|
||||||
@ -76,18 +76,30 @@ float DHT::readHumidity(void) {
|
|||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DHT::computeHeatIndex(float tempFahrenheit, float percentHumidity) {
|
//boolean isFahrenheit: True == Fahrenheit; False == Celcius
|
||||||
|
float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit) {
|
||||||
// Adapted from equation at: https://github.com/adafruit/DHT-sensor-library/issues/9 and
|
// Adapted from equation at: https://github.com/adafruit/DHT-sensor-library/issues/9 and
|
||||||
// Wikipedia: http://en.wikipedia.org/wiki/Heat_index
|
// Wikipedia: http://en.wikipedia.org/wiki/Heat_index
|
||||||
|
if (!isFahrenheit) {
|
||||||
|
return -8.784695 +
|
||||||
|
1.61139411 * temperature +
|
||||||
|
2.338549 * percentHumidity +
|
||||||
|
-0.14611605 * temperature*percentHumidity +
|
||||||
|
-0.01230809 * pow(temperature, 2) +
|
||||||
|
-0.01642482 * pow(percentHumidity, 2) +
|
||||||
|
0.00221173 * pow(temperature, 2) * percentHumidity +
|
||||||
|
0.00072546 * temperature*pow(percentHumidity, 2) +
|
||||||
|
-0.00000358 * pow(temperature, 2) * pow(percentHumidity, 2);
|
||||||
|
}
|
||||||
return -42.379 +
|
return -42.379 +
|
||||||
2.04901523 * tempFahrenheit +
|
2.04901523 * temperature +
|
||||||
10.14333127 * percentHumidity +
|
10.14333127 * percentHumidity +
|
||||||
-0.22475541 * tempFahrenheit*percentHumidity +
|
-0.22475541 * temperature*percentHumidity +
|
||||||
-0.00683783 * pow(tempFahrenheit, 2) +
|
-0.00683783 * pow(temperature, 2) +
|
||||||
-0.05481717 * pow(percentHumidity, 2) +
|
-0.05481717 * pow(percentHumidity, 2) +
|
||||||
0.00122874 * pow(tempFahrenheit, 2) * percentHumidity +
|
0.00122874 * pow(temperature, 2) * percentHumidity +
|
||||||
0.00085282 * tempFahrenheit*pow(percentHumidity, 2) +
|
0.00085282 * temperature*pow(percentHumidity, 2) +
|
||||||
-0.00000199 * pow(tempFahrenheit, 2) * pow(percentHumidity, 2);
|
-0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
2
DHT.h
2
DHT.h
@ -33,7 +33,7 @@ class DHT {
|
|||||||
float readTemperature(bool S=false);
|
float readTemperature(bool S=false);
|
||||||
float convertCtoF(float);
|
float convertCtoF(float);
|
||||||
float convertFtoC(float);
|
float convertFtoC(float);
|
||||||
float computeHeatIndex(float tempFahrenheit, float percentHumidity);
|
float computeHeatIndex(float tempFahrenheit, float percentHumidity, bool isFahrenheit=false);
|
||||||
float readHumidity(void);
|
float readHumidity(void);
|
||||||
boolean read(void);
|
boolean read(void);
|
||||||
|
|
||||||
|
@ -53,9 +53,10 @@ void loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute heat index
|
// Compute heat index in Celsius
|
||||||
// Must send in temp in Fahrenheit!
|
float hic = dht.computeHeatIndex(t, h);
|
||||||
float hi = dht.computeHeatIndex(f, h);
|
// Compute heat index in Fahrenheit
|
||||||
|
float hif = dht.computeHeatIndex(f, h, true);
|
||||||
|
|
||||||
Serial.print("Humidity: ");
|
Serial.print("Humidity: ");
|
||||||
Serial.print(h);
|
Serial.print(h);
|
||||||
@ -66,6 +67,8 @@ void loop() {
|
|||||||
Serial.print(f);
|
Serial.print(f);
|
||||||
Serial.print(" *F\t");
|
Serial.print(" *F\t");
|
||||||
Serial.print("Heat index: ");
|
Serial.print("Heat index: ");
|
||||||
Serial.print(hi);
|
Serial.print(hic);
|
||||||
|
Serial.print(" *C ");
|
||||||
|
Serial.print(hif);
|
||||||
Serial.println(" *F");
|
Serial.println(" *F");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user