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.
Dependencies: mbed DRV88255 TextLCD Ping mbed-rtos
SalinityController.cpp
00001 #include "SalinityController.h" 00002 00003 static AnalogIn salinity_sensor(p19); 00004 static DigitalOut alarmled(LED2); 00005 00006 //Read the sensor, update the local variable. 00007 void SalinityController::update() { 00008 this->salinity = SalinityController::getAdjustedPPT(); 00009 } 00010 00011 //Return the value, this function does not update the value. 00012 float SalinityController::getValue() { 00013 return this->salinity; 00014 } 00015 00016 //Read the voltage, get an average over NUM_MEASUREMENTS values defined in settings.h 00017 float SalinityController::getVoltage() { 00018 float voltage = 0; 00019 float analogin_value = 0; 00020 00021 // Read 0-1.0 value 00022 for(int i = 0; i < NUM_MEASUREMENTS; i++) { 00023 analogin_value += salinity_sensor.read(); 00024 //Thread::wait(MEASUREMENT_DELAY); 00025 } 00026 00027 analogin_value /= (float) NUM_MEASUREMENTS; 00028 voltage = analogin_value * 3.3f * (5.0f/3.0f); 00029 00030 return voltage; 00031 } 00032 00033 //Convert inputvolt to corrected sensor value 00034 float SalinityController::voltToSensor(float inputvolt) { 00035 float slope = 0.7931723; 00036 float intercept = 0.0050561; 00037 00038 float offset = (slope * inputvolt) - intercept; 00039 00040 return inputvolt + offset; 00041 } 00042 00043 //Convert corrected sensor value to actual PPT 00044 float SalinityController::sensorToPPT(float inputvolt) { 00045 float slope = 11.53368; 00046 float intercept = 0.43580; 00047 float minimum = 0.03778499; 00048 00049 if (inputvolt <= minimum) 00050 return 0.00; 00051 00052 return (slope * inputvolt) - intercept; 00053 } 00054 00055 //Chain the needed functions to get the proper PPT 00056 float SalinityController::getAdjustedPPT() { 00057 return sensorToPPT(voltToSensor(getVoltage())); 00058 } 00059 00060 00061 std::string SalinityController::getName() { 00062 return "SalinityController"; 00063 } 00064 00065 void SalinityController::setLed(bool value){ 00066 if (value) alarmled = 1; 00067 if (!value) alarmled = 0; 00068 }
Generated on Tue Jul 12 2022 18:59:29 by
1.7.2