ok

Dependencies:   mbed

Fork of g3_waterplay by Mario Simaremare

Committer:
mariosimaremare
Date:
Tue Jun 07 10:21:07 2016 +0000
Revision:
1:f448c12d2c5b
Parent:
0:ad9362f18797
Child:
2:ed17e258da0d
Salinity and Temperature sensors are working fine.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariosimaremare 0:ad9362f18797 1 /*
mariosimaremare 0:ad9362f18797 2 * G3: WATERPLAY
mariosimaremare 0:ad9362f18797 3 */
mariosimaremare 0:ad9362f18797 4
mariosimaremare 0:ad9362f18797 5 #include "SalinitySensor.h"
mariosimaremare 0:ad9362f18797 6 #include "mbed.h"
mariosimaremare 0:ad9362f18797 7
mariosimaremare 0:ad9362f18797 8 SalinitySensor::SalinitySensor(
mariosimaremare 1:f448c12d2c5b 9 mbed::Serial &serial,
mariosimaremare 0:ad9362f18797 10 PinName pin,
mariosimaremare 0:ad9362f18797 11 double const_voltage,
mariosimaremare 0:ad9362f18797 12 double const_converter,
mariosimaremare 0:ad9362f18797 13 double const_multiplier
mariosimaremare 0:ad9362f18797 14 ):
mariosimaremare 1:f448c12d2c5b 15 _serial(serial),
mariosimaremare 0:ad9362f18797 16 _analog_in(pin),
mariosimaremare 0:ad9362f18797 17 _const_voltage(const_voltage),
mariosimaremare 0:ad9362f18797 18 _const_converter(const_converter),
mariosimaremare 1:f448c12d2c5b 19 _const_multiplier(const_multiplier),
mariosimaremare 1:f448c12d2c5b 20 _reading(0.0),
mariosimaremare 1:f448c12d2c5b 21 _voltage(0.0),
mariosimaremare 1:f448c12d2c5b 22 _salinity(0.0)
mariosimaremare 0:ad9362f18797 23 {
mariosimaremare 1:f448c12d2c5b 24 this->read();
mariosimaremare 1:f448c12d2c5b 25
mariosimaremare 0:ad9362f18797 26 }
mariosimaremare 0:ad9362f18797 27
mariosimaremare 0:ad9362f18797 28 double SalinitySensor::read()
mariosimaremare 0:ad9362f18797 29 {
mariosimaremare 1:f448c12d2c5b 30 // the reading from sensor.
mariosimaremare 1:f448c12d2c5b 31 this->_reading = this->_analog_in.read();
mariosimaremare 1:f448c12d2c5b 32 // converted voltage.
mariosimaremare 1:f448c12d2c5b 33 this->_voltage =
mariosimaremare 1:f448c12d2c5b 34 this->_reading *
mariosimaremare 1:f448c12d2c5b 35 this->_const_voltage *
mariosimaremare 1:f448c12d2c5b 36 this->_const_converter;
mariosimaremare 1:f448c12d2c5b 37 // the salinity value.
mariosimaremare 1:f448c12d2c5b 38 this->_salinity =
mariosimaremare 1:f448c12d2c5b 39 this->_voltage *
mariosimaremare 1:f448c12d2c5b 40 this->_const_multiplier;
mariosimaremare 0:ad9362f18797 41
mariosimaremare 1:f448c12d2c5b 42 /*
mariosimaremare 1:f448c12d2c5b 43 _serial.printf(
mariosimaremare 1:f448c12d2c5b 44 "\tsalinity: %5.4F | %5.4F | %5.4F\n\r",
mariosimaremare 1:f448c12d2c5b 45 this->_reading,
mariosimaremare 1:f448c12d2c5b 46 this->_voltage,
mariosimaremare 1:f448c12d2c5b 47 this->_salinity
mariosimaremare 1:f448c12d2c5b 48 );
mariosimaremare 1:f448c12d2c5b 49 */
mariosimaremare 1:f448c12d2c5b 50
mariosimaremare 1:f448c12d2c5b 51 return(this->_reading);
mariosimaremare 0:ad9362f18797 52 }
mariosimaremare 0:ad9362f18797 53
mariosimaremare 0:ad9362f18797 54 double SalinitySensor::getVoltage()
mariosimaremare 0:ad9362f18797 55 {
mariosimaremare 1:f448c12d2c5b 56 return(this->_voltage);
mariosimaremare 0:ad9362f18797 57 }
mariosimaremare 0:ad9362f18797 58
mariosimaremare 0:ad9362f18797 59 double SalinitySensor::getSalinity()
mariosimaremare 0:ad9362f18797 60 {
mariosimaremare 1:f448c12d2c5b 61 return(this->_salinity);
mariosimaremare 0:ad9362f18797 62 }