Skip to content

Commit

Permalink
Merge branch 'MyIgel-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
tdicola committed Jun 26, 2015
2 parents b6925ee + ef9590a commit a1393fc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
38 changes: 27 additions & 11 deletions DHT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void DHT::begin(void) {
_lastreadtime = 0;
}

//boolean S == Scale. True == Farenheit; False == Celcius
//boolean S == Scale. True == Fahrenheit; False == Celcius
float DHT::readTemperature(bool S) {
float f = NAN;

Expand Down Expand Up @@ -78,18 +78,34 @@ float DHT::readHumidity(void) {
return f;
}

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
// Wikipedia: http://en.wikipedia.org/wiki/Heat_index
return -42.379 +
2.04901523 * tempFahrenheit +
10.14333127 * percentHumidity +
-0.22475541 * tempFahrenheit*percentHumidity +
-0.00683783 * pow(tempFahrenheit, 2) +
-0.05481717 * pow(percentHumidity, 2) +
0.00122874 * pow(tempFahrenheit, 2) * percentHumidity +
0.00085282 * tempFahrenheit*pow(percentHumidity, 2) +
-0.00000199 * pow(tempFahrenheit, 2) * pow(percentHumidity, 2);
if (!isFahrenheit) {
// Celsius heat index calculation.
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);
}
else {
// Fahrenheit heat index calculation.
return -42.379 +
2.04901523 * temperature +
10.14333127 * percentHumidity +
-0.22475541 * temperature*percentHumidity +
-0.00683783 * pow(temperature, 2) +
-0.05481717 * pow(percentHumidity, 2) +
0.00122874 * pow(temperature, 2) * percentHumidity +
0.00085282 * temperature*pow(percentHumidity, 2) +
-0.00000199 * pow(temperature, 2) * pow(percentHumidity, 2);
}
}

boolean DHT::read(void) {
Expand Down
2 changes: 1 addition & 1 deletion DHT.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DHT {
float readTemperature(bool S=false);
float convertCtoF(float);
float convertFtoC(float);
float computeHeatIndex(float tempFahrenheit, float percentHumidity);
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
float readHumidity(void);
boolean read(void);

Expand Down
15 changes: 9 additions & 6 deletions examples/DHTtester/DHTtester.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
Expand All @@ -48,9 +48,10 @@ void loop() {
return;
}

// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);

Serial.print("Humidity: ");
Serial.print(h);
Expand All @@ -61,6 +62,8 @@ void loop() {
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hi);
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}

0 comments on commit a1393fc

Please sign in to comment.