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

Committer:
joran
Date:
Fri Jun 10 10:53:56 2016 +0000
Revision:
6:067e999b9c6e
Parent:
4:4011a1562a77
Child:
7:8b3aef52aa7b
Child:
8:24b057cbcb53
Hopelijk gaat dit goed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
6366295 0:dab140a197e0 1 #include "SalinityController.h"
6366295 0:dab140a197e0 2
6366295 0:dab140a197e0 3 AnalogIn salinity_sensor(p19);
6366295 0:dab140a197e0 4
6366295 0:dab140a197e0 5 SalinityController::SalinityController()
6366295 0:dab140a197e0 6 {
6366295 0:dab140a197e0 7 printf("Initiate Salinity Controller\r\n");
6366295 0:dab140a197e0 8 }
6366295 0:dab140a197e0 9
6366295 0:dab140a197e0 10 // Function reads sensor values and averages N sensor values
6366295 0:dab140a197e0 11 float SalinityController::readSensor()
6366295 0:dab140a197e0 12 {
6366295 0:dab140a197e0 13 float analogin_value = 0;
6366295 0:dab140a197e0 14 float ppt = 0;
6366295 0:dab140a197e0 15
6366295 0:dab140a197e0 16 // Read 0-1.0 value
6366295 0:dab140a197e0 17 for(int i = 0; i < N; i++)
6366295 0:dab140a197e0 18 {
6366295 0:dab140a197e0 19 analogin_value += salinity_sensor.read();
6366295 0:dab140a197e0 20 }
6366295 0:dab140a197e0 21 // Average 10 sensor values
6366295 0:dab140a197e0 22 analogin_value /= (float) N;
6366295 0:dab140a197e0 23
6366295 0:dab140a197e0 24 ppt = analoginToPPT(analogin_value);
6366295 0:dab140a197e0 25
6366295 0:dab140a197e0 26 return ppt;
6366295 0:dab140a197e0 27 }
6366295 0:dab140a197e0 28
6366295 0:dab140a197e0 29 // Function converts average sensor value to ppt
6366295 0:dab140a197e0 30 float SalinityController::analoginToPPT(float analogin_value)
6366295 0:dab140a197e0 31 {
6366295 0:dab140a197e0 32 float voltage = 0;
6366295 0:dab140a197e0 33 float ppt = 0;
6366295 0:dab140a197e0 34
6366295 0:dab140a197e0 35 // Convert average sensor value to value with range 0-5.0v
6366295 0:dab140a197e0 36 voltage = analogin_value * 3.3f * (5.0f/3.0f);
6366295 0:dab140a197e0 37
joran 6:067e999b9c6e 38 // printf("Sensor Voltage: %f \t", voltage);
6366295 1:eb527bc93b62 39
6366295 0:dab140a197e0 40 // Convert voltage to ppt
6366295 4:4011a1562a77 41 // ppt = voltage * 16.3;
6366295 4:4011a1562a77 42 ppt = voltage * 15.1747217178 - 2.89491343498;
6366295 0:dab140a197e0 43
6366295 0:dab140a197e0 44 return ppt;
6366295 0:dab140a197e0 45 }
6366295 0:dab140a197e0 46
joran 6:067e999b9c6e 47 float SalinityController::getPPT()
joran 6:067e999b9c6e 48 {
joran 6:067e999b9c6e 49 float ppt = 0;
joran 6:067e999b9c6e 50
joran 6:067e999b9c6e 51 ppt = readSensor();
joran 6:067e999b9c6e 52
joran 6:067e999b9c6e 53 return ppt;
joran 6:067e999b9c6e 54 }
joran 6:067e999b9c6e 55
joran 6:067e999b9c6e 56 float SalinityController::getVoltage()
joran 6:067e999b9c6e 57 {
joran 6:067e999b9c6e 58 float voltage = 0;
joran 6:067e999b9c6e 59
joran 6:067e999b9c6e 60 float analogin_value = 0;
joran 6:067e999b9c6e 61 float ppt = 0;
joran 6:067e999b9c6e 62
joran 6:067e999b9c6e 63 // Read 0-1.0 value
joran 6:067e999b9c6e 64 for(int i = 0; i < N; i++)
joran 6:067e999b9c6e 65 {
joran 6:067e999b9c6e 66 analogin_value += salinity_sensor.read();
joran 6:067e999b9c6e 67 }
joran 6:067e999b9c6e 68 // Average 10 sensor values
joran 6:067e999b9c6e 69 analogin_value /= (float) N;
joran 6:067e999b9c6e 70 voltage = analogin_value * 3.3f * (5.0f/3.0f);
joran 6:067e999b9c6e 71
joran 6:067e999b9c6e 72 return voltage;
joran 6:067e999b9c6e 73 }
joran 6:067e999b9c6e 74
6366295 0:dab140a197e0 75 // Function prints salinity sensor value in ppt
6366295 0:dab140a197e0 76 void SalinityController::displayPPT()
6366295 0:dab140a197e0 77 {
6366295 0:dab140a197e0 78 float ppt = 0;
6366295 0:dab140a197e0 79
6366295 0:dab140a197e0 80 ppt = readSensor();
6366295 0:dab140a197e0 81
6366295 0:dab140a197e0 82 printf("Salinity: %f ppt\t", ppt);
6366295 0:dab140a197e0 83 }