finitespace / BME280

Provides an Arduino library for reading and interpreting Bosch BME280 data over I2C, SPI or Sw SPI.
GNU General Public License v3.0
212 stars 105 forks source link

Enhancement: Add HeatIndex #45

Closed coelner closed 6 years ago

coelner commented 7 years ago

we can calculate the heatindex from the rel. humidity and the temperature. https://en.wikipedia.org/wiki/Heat_index

coelner commented 6 years ago

a fast brain dump

int Heatindex
(
  float temperature,
  float humidity,
  bool metric
)
{
  float heatindex = NAN;
  float hi[2][9] = { {-8.784695,1.61139411,2.338549,-0.14611605,-1.2308094/100,-1.6424828/100,2.211732/1000,7.2546/10000,-3.582/1000000},
  {-42.379,2.04901523,10.1433127,-0.22475541,-6.83783/1000,-5.481717/100,1.22874/1000,8.5282/10000,-1.99/1000000} };

  //taken from https://de.wikipedia.org/wiki/Hitzeindex#Berechnung
  if (!isnan(humidity) && !isnan(temperature) && humidity>40 && (metric ? temperature>26.7 : temperature>80)) {
    heatindex =  hi[metric ? 0: 1][0];
    heatindex =+ hi[metric ? 0: 1][1] * temperature;
    heatindex =+ hi[metric ? 0: 1][2] * humidity;
    heatindex =+ hi[metric ? 0: 1][3] * temperature * humidity;
    heatindex =+ hi[metric ? 0: 1][4] * temperature * temperature;
    heatindex =+ hi[metric ? 0: 1][5] * humidity * humidity;
    heatindex =+ hi[metric ? 0: 1][6] * temperature * temperature * humidity;
    heatindex =+ hi[metric ? 0: 1][7] * temperature * humidity * humidity;
    heatindex =+ hi[metric ? 0: 1][8] * temperature * temperature * humidity * humidity;
    return int(heatindex);
  }
  else {
    return NAN;
  }
}
finitespace commented 6 years ago

This look cool! If you can submit a pull request with documentation, that would be wonderful!

coelner commented 6 years ago

57