Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of g3_waterplay by
Diff: TemperatureSensor.cpp
- Revision:
- 0:ad9362f18797
- Child:
- 1:f448c12d2c5b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TemperatureSensor.cpp Thu Jun 02 17:53:02 2016 +0000 @@ -0,0 +1,56 @@ +/* +* G3: WATERPLAY +*/ + +#include "TemperatureSensor.h" +#include "mbed.h" + +TemperatureSensor::TemperatureSensor( + PinName pin, + double const_voltage, + double const_converter, + double variance, + double vin, + double resistance +): + _analog_in(pin), + _const_voltage(const_voltage), + _const_converter(const_converter), + _variance(variance), + _vin(vin), + _resistance(resistance), + _k0(0.00102119), + _k1(0.000222468), + _k2(0.000000133342), + _kelvin_to_celcius(-273.15) +{ + read(); +} + +double TemperatureSensor::read() +{ + _voltage = _analog_in.read(); + + return(_voltage); +} + +double TemperatureSensor::getVoltage() +{ + float retVal = _voltage * _const_voltage; + + return(retVal); +} + +double TemperatureSensor::getTemperature() +{ + double vout = getVoltage(); + double RT = (vout * _resistance) / (_vin - vout); + double logRT = log(RT); + double K0 = _k0; + double K1 = _k1 * logRT; + double K2 = _k2 * pow(logRT, 3.0); + double kelvin = 1.0 / (K0 + K1 + K2); + double celcius = (kelvin + _kelvin_to_celcius) + _variance; + + return(celcius); +}