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: SalinitySensor.cpp
- Revision:
- 5:4cbe44452889
- Parent:
- 3:7c648d1d8802
--- a/SalinitySensor.cpp Fri Jun 17 09:24:01 2016 +0000 +++ b/SalinitySensor.cpp Fri Jun 17 11:03:37 2016 +0000 @@ -9,21 +9,10 @@ SalinitySensor::SalinitySensor( Printer &printer, - PinName pin, - double const_voltage, - double const_converter, - double const_multiplier, - double const_lower_boundary, - double const_upper_boundary + PinName pin ): _printer(printer), _analog_in(pin), - _const_voltage(const_voltage), - _const_converter(const_converter), - _const_multiplier(const_multiplier), - _const_lower_boundary(const_lower_boundary), - _const_upper_boundary(const_upper_boundary), - _const_sample_number(100), _reading(0.0), _voltage(0.0), _salinity(0.0), @@ -35,34 +24,34 @@ void SalinitySensor::reload() { - double readings[this->_const_sample_number]; + double readings[SAMPLING_NUMBER]; - for(int counter = 0; counter < this->_const_sample_number; ++counter){ + for(int counter = 0; counter < SAMPLING_NUMBER; ++counter){ // the reading from sensor. readings[counter] = this->_analog_in.read(); } - sort(readings, readings + this->_const_sample_number); + sort(readings, readings + SAMPLING_NUMBER); - this->_reading = readings[this->_const_sample_number / 2]; + this->_reading = readings[SAMPLING_NUMBER / 2]; // converted voltage. this->_voltage = this->_reading * - this->_const_voltage * - this->_const_converter; + VIN * + CONVERTER; // the salinity value. this->_salinity = this->_voltage * - this->_const_multiplier; + MULTIPLIER; this->_status = 0.0; this->_strStatus = "OK"; - if(this->_salinity < this->_const_lower_boundary){ - this->_status = this->_salinity - this->_const_lower_boundary; + if(this->_salinity < LOWER_BOUNDARY){ + this->_status = this->_salinity - LOWER_BOUNDARY; this->_strStatus = "LW"; - } else if(this->_salinity > this->_const_upper_boundary){ - this->_status = this->_const_lower_boundary - this->_salinity; + } else if(this->_salinity > UPPER_BOUNDARY){ + this->_status = UPPER_BOUNDARY - this->_salinity; this->_strStatus = "HI"; } }