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:
6366295
Date:
2016-06-06
Revision:
1:eb527bc93b62
Parent:
0:dab140a197e0
Child:
4:4011a1562a77

File content as of revision 1:eb527bc93b62:

#include "SalinityController.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);
    
    printf("Sensor Voltage: %f \t", voltage);
    
    // 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);
}