Program for the water play project for the course Software Testing Practical 2016 given at the VU University
Dependencies: mbed DRV88255 TextLCD Ping mbed-rtos
SalinityController.cpp
- Committer:
- joran
- Date:
- 2016-06-15
- Revision:
- 42:e7c726f9c6ed
- Parent:
- 32:1e4919a44196
- Child:
- 58:b5f0c0f305ff
File content as of revision 42:e7c726f9c6ed:
#include "SalinityController.h" AnalogIn salinity_sensor(p19); //Read the sensor, update the local variable. void SalinityController::update() { this->salinity = SalinityController::getAdjustedPPT(); } //Return the value, this function does not update the value. float SalinityController::getValue() { return this->salinity; } //Read the voltage, get an average over N values. float SalinityController::getVoltage() { float voltage = 0; float analogin_value = 0; // Read 0-1.0 value for(int i = 0; i < N; i++) { analogin_value += salinity_sensor.read(); } // Average 10 sensor values analogin_value /= (float) N; voltage = analogin_value * 3.3f * (5.0f/3.0f); return voltage; } //Convert inputvolt to corrected sensor value float SalinityController::voltToSensor(float inputvolt) { float slope = 0.7931723; float intercept = 0.0050561; float offset = (slope * inputvolt) - intercept; return inputvolt + offset; } //Convert corrected sensor value to actual PPT float SalinityController::sensorToPPT(float inputvolt) { float minimum = 0.03778499; if (inputvolt <= minimum) return 0.00; float slope = 11.53368; float intercept = 0.43580; float ppt = (slope * inputvolt) - intercept; return ppt; } //Chain the needed functions to get the proper PPT float SalinityController::getAdjustedPPT() { return sensorToPPT(voltToSensor(getVoltage())); } std::string SalinityController::get_name() { return "SalinityController"; }