mirror of
https://github.com/adafruit/DHT-sensor-library.git
synced 2023-10-23 22:20:38 +03:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
56058fecc5 | |||
d71288af17 | |||
ce3190f65c | |||
5bc0a5c796 | |||
5fb1668822 | |||
c57f0c8c29 | |||
51a8b814ac | |||
36fb16274b |
44
DHT.cpp
44
DHT.cpp
@ -46,7 +46,7 @@ float DHT::readTemperature(bool S, bool force) {
|
|||||||
f = data[2] & 0x7F;
|
f = data[2] & 0x7F;
|
||||||
f *= 256;
|
f *= 256;
|
||||||
f += data[3];
|
f += data[3];
|
||||||
f /= 10;
|
f *= 0.1;
|
||||||
if (data[2] & 0x80) {
|
if (data[2] & 0x80) {
|
||||||
f *= -1;
|
f *= -1;
|
||||||
}
|
}
|
||||||
@ -60,11 +60,11 @@ float DHT::readTemperature(bool S, bool force) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
float DHT::convertCtoF(float c) {
|
float DHT::convertCtoF(float c) {
|
||||||
return c * 9 / 5 + 32;
|
return c * 1.8 + 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DHT::convertFtoC(float f) {
|
float DHT::convertFtoC(float f) {
|
||||||
return (f - 32) * 5 / 9;
|
return (f - 32) * 0.55555;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DHT::readHumidity(bool force) {
|
float DHT::readHumidity(bool force) {
|
||||||
@ -79,7 +79,7 @@ float DHT::readHumidity(bool force) {
|
|||||||
f = data[0];
|
f = data[0];
|
||||||
f *= 256;
|
f *= 256;
|
||||||
f += data[1];
|
f += data[1];
|
||||||
f /= 10;
|
f *= 0.1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -88,23 +88,17 @@ float DHT::readHumidity(bool force) {
|
|||||||
|
|
||||||
//boolean isFahrenheit: True == Fahrenheit; False == Celcius
|
//boolean isFahrenheit: True == Fahrenheit; False == Celcius
|
||||||
float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit) {
|
float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit) {
|
||||||
// Adapted from equation at: https://github.com/adafruit/DHT-sensor-library/issues/9 and
|
// Using both Rothfusz and Steadman's equations
|
||||||
// Wikipedia: http://en.wikipedia.org/wiki/Heat_index
|
// http://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
|
||||||
if (!isFahrenheit) {
|
float hi;
|
||||||
// Celsius heat index calculation.
|
|
||||||
return -8.784695 +
|
if (!isFahrenheit)
|
||||||
1.61139411 * temperature +
|
temperature = convertCtoF(temperature);
|
||||||
2.338549 * percentHumidity +
|
|
||||||
-0.14611605 * temperature*percentHumidity +
|
hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));
|
||||||
-0.01230809 * pow(temperature, 2) +
|
|
||||||
-0.01642482 * pow(percentHumidity, 2) +
|
if (hi > 79) {
|
||||||
0.00221173 * pow(temperature, 2) * percentHumidity +
|
hi = -42.379 +
|
||||||
0.00072546 * temperature*pow(percentHumidity, 2) +
|
|
||||||
-0.00000358 * pow(temperature, 2) * pow(percentHumidity, 2);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Fahrenheit heat index calculation.
|
|
||||||
return -42.379 +
|
|
||||||
2.04901523 * temperature +
|
2.04901523 * temperature +
|
||||||
10.14333127 * percentHumidity +
|
10.14333127 * percentHumidity +
|
||||||
-0.22475541 * temperature*percentHumidity +
|
-0.22475541 * temperature*percentHumidity +
|
||||||
@ -113,7 +107,15 @@ float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFah
|
|||||||
0.00122874 * pow(temperature, 2) * percentHumidity +
|
0.00122874 * pow(temperature, 2) * percentHumidity +
|
||||||
0.00085282 * temperature*pow(percentHumidity, 2) +
|
0.00085282 * temperature*pow(percentHumidity, 2) +
|
||||||
-0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);
|
-0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);
|
||||||
|
|
||||||
|
if((percentHumidity < 13) && (temperature >= 80.0) && (temperature <= 112.0))
|
||||||
|
hi -= ((13.0 - percentHumidity) * 0.25) * sqrt((17.0 - abs(temperature - 95.0)) * 0.05882);
|
||||||
|
|
||||||
|
else if((percentHumidity > 85.0) && (temperature >= 80.0) && (temperature <= 87.0))
|
||||||
|
hi += ((percentHumidity - 85.0) * 0.1) * ((87.0 - temperature) * 0.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return isFahrenheit ? hi : convertFtoC(hi);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean DHT::read(bool force) {
|
boolean DHT::read(bool force) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=DHT sensor library
|
name=DHT sensor library
|
||||||
version=1.2.0
|
version=1.2.2
|
||||||
author=Adafruit
|
author=Adafruit
|
||||||
maintainer=Adafruit <info@adafruit.com>
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors
|
sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors
|
||||||
|
Reference in New Issue
Block a user