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: SalinitySensor.cpp
- Revision:
- 1:f448c12d2c5b
- Parent:
- 0:ad9362f18797
- Child:
- 2:ed17e258da0d
--- a/SalinitySensor.cpp Thu Jun 02 17:53:02 2016 +0000
+++ b/SalinitySensor.cpp Tue Jun 07 10:21:07 2016 +0000
@@ -6,36 +6,57 @@
#include "mbed.h"
SalinitySensor::SalinitySensor(
+ mbed::Serial &serial,
PinName pin,
double const_voltage,
double const_converter,
double const_multiplier
):
+ _serial(serial),
_analog_in(pin),
_const_voltage(const_voltage),
_const_converter(const_converter),
- _const_multiplier(const_multiplier)
+ _const_multiplier(const_multiplier),
+ _reading(0.0),
+ _voltage(0.0),
+ _salinity(0.0)
{
- read();
+ this->read();
+
}
double SalinitySensor::read()
{
- _voltage = _analog_in.read();
+ // the reading from sensor.
+ this->_reading = this->_analog_in.read();
+ // converted voltage.
+ this->_voltage =
+ this->_reading *
+ this->_const_voltage *
+ this->_const_converter;
+ // the salinity value.
+ this->_salinity =
+ this->_voltage *
+ this->_const_multiplier;
- return(_voltage);
+ /*
+ _serial.printf(
+ "\tsalinity: %5.4F | %5.4F | %5.4F\n\r",
+ this->_reading,
+ this->_voltage,
+ this->_salinity
+ );
+ */
+
+ return(this->_reading);
}
double SalinitySensor::getVoltage()
{
- double retVal = _voltage * _const_voltage * _const_converter;
-
- return(retVal);
+ return(this->_voltage);
}
double SalinitySensor::getSalinity()
{
- double retVal = getVoltage() * _const_multiplier;
-
- return(retVal);
+ return(this->_salinity);
}