GY-63_MS5611/libraries/Temperature/temperature.h

128 lines
4.1 KiB
C
Raw Normal View History

2020-11-27 05:33:55 -05:00
#pragma once
2015-03-07 16:44:21 -05:00
//
// FILE: temperature.h
2022-04-15 14:19:05 -04:00
// VERSION: 0.3.4
2021-12-28 13:11:26 -05:00
// DATE: 2015-03-29
// PURPOSE: collection temperature functions
2020-11-27 05:33:55 -05:00
2022-04-15 14:19:05 -04:00
#include "Arduino.h"
2022-01-09 14:35:35 -05:00
2015-03-07 16:44:21 -05:00
2022-04-15 14:19:05 -04:00
#define TEMPERATURE_VERSION (F("0.3.4"))
2015-03-07 16:44:21 -05:00
2022-04-15 14:19:05 -04:00
float Fahrenheit(float celsius);
2015-03-07 16:44:21 -05:00
2022-04-15 14:19:05 -04:00
float Celsius(float Fahrenheit);
2015-03-07 16:44:21 -05:00
2022-04-15 14:19:05 -04:00
float Kelvin(float celsius);
2015-03-07 16:44:21 -05:00
2020-11-27 05:33:55 -05:00
// reference:
// [1] https://wahiduddin.net/calc/density_algorithms.htm
// [2] https://web.archive.org/web/20100528030817/https://www.colorado.edu/geography/weather_station/Geog_site/about.htm
// dewPoint function based on code of [2]
2021-12-28 13:11:26 -05:00
// calculation of the saturation vapour pressure part is based upon NOAA ESGG(temp)
2022-04-15 14:19:05 -04:00
float dewPoint(float celsius, float humidity);
2015-03-07 16:44:21 -05:00
2020-11-27 05:33:55 -05:00
// dewPointFast() is > 5x faster than dewPoint() - run dewpoint_test.ino
2021-12-28 13:11:26 -05:00
// delta mdewPointFastax with dewPoint() - run dewpoint_test.ino ==> ~0.347
// (earlier version mentions ~0.6544 but that test code is gone :(
2020-11-27 05:33:55 -05:00
// http://en.wikipedia.org/wiki/Dew_point
2022-04-15 14:19:05 -04:00
float dewPointFast(float celsius, float humidity);
2015-03-07 16:44:21 -05:00
2020-11-27 05:33:55 -05:00
// https://en.wikipedia.org/wiki/Humidex
2022-04-15 14:19:05 -04:00
float humidex(float celsius, float dewPoint);
2015-03-07 16:44:21 -05:00
2022-01-06 09:32:26 -05:00
// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
// previous https://en.wikipedia.org/wiki/Heat_index
2020-11-27 05:33:55 -05:00
// TF = temp in Fahrenheit
2022-01-06 09:32:26 -05:00
// RH = relative humidity in %
2022-04-15 14:19:05 -04:00
float heatIndex(float TF, float RH);
2015-03-07 16:44:21 -05:00
2020-11-27 05:33:55 -05:00
2022-01-06 09:32:26 -05:00
// 0.3.0 => https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
// previous https://en.wikipedia.org/wiki/Heat_index
2022-01-09 14:35:35 -05:00
// TC = temp in Celsius
// RH = relative humidity in %
2022-04-15 14:19:05 -04:00
float heatIndexC(float TC, float RH);
2015-03-07 16:44:21 -05:00
2020-11-27 05:33:55 -05:00
// https://en.wikipedia.org/wiki/Wind_chill
2022-01-09 14:35:35 -05:00
// US = Fahrenheit / miles / hour
// METRIC = Celsius / meter / hour (sec)
2021-12-28 13:11:26 -05:00
// wind speed @ 10 meter,
// if convert is true => wind speed will be converted to 1.5 meter
// else ==> formula assumes wind speed @ 1.5 meter
2015-03-07 16:44:21 -05:00
2021-01-29 06:31:58 -05:00
2020-11-27 05:33:55 -05:00
// US
2022-04-15 14:19:05 -04:00
float WindChill_F_mph(const float Fahrenheit, const float milesPerHour, const bool convert = true);
2021-01-29 06:31:58 -05:00
2022-01-09 14:35:35 -05:00
// METRIC - standard wind chill formula for Environment Canada
2022-04-15 14:19:05 -04:00
float WindChill_C_kmph(const float Celsius, const float kilometerPerHour, const bool convert = true);
2022-01-09 05:07:58 -05:00
2022-04-15 14:19:05 -04:00
float WindChill_C_mps(const float Celsius, const float meterPerSecond, const bool convert = true);
2015-03-07 16:44:21 -05:00
2021-01-29 06:31:58 -05:00
2022-01-09 05:07:58 -05:00
// https://www.engineeringtoolbox.com/air-altitude-pressure-d_462.html
// Does not have the temperature correction ==> it has almost the -5.257 exponent
// https://www.omnicalculator.com/physics/air-pressure-at-altitude
// similar to https://en.wikipedia.org/wiki/Barometric_formula
//
// Note: altitude in meters.
2022-04-15 14:19:05 -04:00
float baroToSeaLevelC( float pressure, float celsius, float altitude);
// https://www.omnicalculator.com/physics/air-pressure-at-altitude
// temperature (Celsius) at altitude (meter)
float seaLevelToAltitude( float pressureSeaLevel, float celsius, float altitude);
float altitudeToSeaLevel( float pressure, float celsius, float altitude);
2015-03-07 16:44:21 -05:00
2020-11-27 05:33:55 -05:00
2022-01-09 05:07:58 -05:00
/////////////////////////////////////////////////////////////
//
// TEMPERATURE CONVERTER CLASS
//
class temperatureConverter
{
// used Celsius as internal unit, to minimize math
public:
temperatureConverter() { _temp = 0; };
void setKelvin(float value = 0) { _temp = value - 273.15; };
void setCelsius(float value = 0) { _temp = value; };
void setFahrenheit(float value = 0) { _temp = (value - 32.0) / 1.8; };
void setReamur(float value = 0) { _temp = value * 1.25; };
void setRankine(float value = 0) { _temp = (value - 491.67) / 1.8; };
void setDelisle(float value = 0) { _temp = (value + 100) / 1.5; };
void setNewton(float value = 0) { _temp = value / 0.33; };
void setRomer(float value = 0) { _temp = (value - 7.5) / 0.525; };
float getKelvin() { return _temp + 273.15; };
float getCelsius() { return _temp; };
float getFahrenheit() { return _temp * 1.8 + 32; };
float getReamur() { return _temp * 0.8; };
float getRankine() { return _temp * 1.8 + 491.67; };
float getDelisle() { return _temp * 1.5 - 100.0; };
float getNewton() { return _temp * 0.33; };
float getRomer() { return _temp * 0.525 + 7.5; };
private:
float _temp = 0;
};
2020-11-27 05:33:55 -05:00
// -- END OF FILE --
2021-12-28 13:11:26 -05:00