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
TemperatureSensor.cpp
- Committer:
- mariosimaremare
- Date:
- 2016-06-07
- Revision:
- 1:f448c12d2c5b
- Parent:
- 0:ad9362f18797
- Child:
- 2:ed17e258da0d
File content as of revision 1:f448c12d2c5b:
/* * G3: WATERPLAY */ #include "TemperatureSensor.h" #include "mbed.h" TemperatureSensor::TemperatureSensor( mbed::Serial &serial, PinName pin, double const_voltage, double const_converter, double variance, double vin, double resistance ): _serial(serial), _analog_in(pin), _const_voltage(const_voltage), _const_converter(const_converter), _variance(variance), _vin(vin), _resistance(resistance), _temperature(0.0), _k0(0.00102119), _k1(0.000222468), _k2(0.000000133342), _kelvin_to_celcius(-273.15) { read(); } double TemperatureSensor::read() { this->_reading = _analog_in.read(); this->_voltage = this->_reading * _const_voltage; this->_voltage = this->_reading * _const_voltage; double RT = (this->_voltage * _resistance) / (_vin - this->_voltage); double logRT = log(RT); double K0 = this->_k0; double K1 = this->_k1 * logRT; double K2 = this->_k2 * pow(logRT, 3.0); double kelvin = 1.0 / (K0 + K1 + K2); this->_temperature = (kelvin + this->_kelvin_to_celcius) + this->_variance; /* _serial.printf( "\ttemperature: %5.4F | %5.4F | %5.4F\n\r", this->_reading, this->_voltage, this->_temperature ); */ return(this->_reading); } double TemperatureSensor::getVoltage() { return(this->_voltage); } double TemperatureSensor::getTemperature() { return(this->_temperature); }