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.
Diff: TemperatureSensor.cpp
- Revision:
- 2:ed17e258da0d
- Parent:
- 1:f448c12d2c5b
- Child:
- 3:7c648d1d8802
diff -r f448c12d2c5b -r ed17e258da0d TemperatureSensor.cpp
--- a/TemperatureSensor.cpp Tue Jun 07 10:21:07 2016 +0000
+++ b/TemperatureSensor.cpp Tue Jun 14 09:14:24 2016 +0000
@@ -10,6 +10,8 @@
PinName pin,
double const_voltage,
double const_converter,
+ double const_lower_boundary,
+ double const_upper_boundary,
double variance,
double vin,
double resistance
@@ -18,43 +20,57 @@
_analog_in(pin),
_const_voltage(const_voltage),
_const_converter(const_converter),
+ _const_lower_boundary(const_lower_boundary),
+ _const_upper_boundary(const_upper_boundary),
_variance(variance),
_vin(vin),
_resistance(resistance),
+ _reading(0.0),
+ _voltage(0.0),
_temperature(0.0),
+ _status(0.0),
_k0(0.00102119),
_k1(0.000222468),
_k2(0.000000133342),
_kelvin_to_celcius(-273.15)
{
- read();
+ this->reload();
}
-double TemperatureSensor::read()
+void TemperatureSensor::reload()
{
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);
+ this->_voltage = this->_reading * this->_const_voltage * this->_const_converter;
+ double RT = (this->_voltage * this->_resistance) / (this->_vin - this->_voltage);
double logRT = log(RT);
- double K0 = this->_k0;
+ 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;
- /*
+ this->_status = 0.0;
+ if(this->_temperature < this->_const_lower_boundary){
+ this->_status = this->_temperature - this->_const_lower_boundary;
+ } else if(this->_temperature > this->_const_upper_boundary){
+ this->_status = this->_temperature - this->_const_upper_boundary;
+ }
+
_serial.printf(
"\ttemperature: %5.4F | %5.4F | %5.4F\n\r",
this->_reading,
this->_voltage,
this->_temperature
);
- */
+}
+
+double TemperatureSensor::getReading()
+{
return(this->_reading);
}
+
double TemperatureSensor::getVoltage()
{
return(this->_voltage);
@@ -64,3 +80,8 @@
{
return(this->_temperature);
}
+
+double TemperatureSensor::getStatus()
+{
+ return(this->_status);
+}
\ No newline at end of file