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

Revision:
0:dab140a197e0
Child:
1:eb527bc93b62
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SalinityController.cpp	Fri Jun 03 14:24:25 2016 +0000
@@ -0,0 +1,54 @@
+#include "SalinityController.h"
+
+#include "stdio.h"
+
+AnalogIn salinity_sensor(p19);
+
+SalinityController::SalinityController()
+{
+    printf("Initiate Salinity Controller\r\n");
+}
+
+// Function reads sensor values and averages N sensor values
+float SalinityController::readSensor()
+{
+    float analogin_value = 0;
+    float ppt = 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;
+    
+    ppt = analoginToPPT(analogin_value);
+    
+    return ppt;
+}
+
+// Function converts average sensor value to ppt
+float SalinityController::analoginToPPT(float analogin_value)
+{
+    float voltage = 0;
+    float ppt = 0;
+    
+    // Convert average sensor value to value with range 0-5.0v
+    voltage = analogin_value * 3.3f * (5.0f/3.0f);
+    
+    // Convert voltage to ppt
+    ppt = voltage * 16.3;
+    
+    return ppt;
+}
+
+// Function prints salinity sensor value in ppt
+void SalinityController::displayPPT()
+{
+    float ppt = 0;
+    
+    ppt = readSensor();
+    
+    printf("Salinity: %f ppt\t", ppt);
+}
\ No newline at end of file