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
Diff: TemperatureController.cpp
- Revision:
- 8:24b057cbcb53
- Parent:
- 6:067e999b9c6e
- Child:
- 10:fd4670ec0806
diff -r 067e999b9c6e -r 24b057cbcb53 TemperatureController.cpp --- a/TemperatureController.cpp Fri Jun 10 10:53:56 2016 +0000 +++ b/TemperatureController.cpp Fri Jun 10 12:38:54 2016 +0000 @@ -1,4 +1,5 @@ #include "TemperatureController.h" +#include "rtos.h" AnalogIn temperature_sensor(p20); DigitalOut heater(p18); @@ -8,18 +9,37 @@ printf("Initiate Temperature Controller\r\n"); } + +float TemperatureController::getValue() { + return this->temperature; +} + +void TemperatureController::update() { + this->temperature = readSensor(); +} + // Function reads sensor values and averages N sensor values float TemperatureController::readSensor() { float analogin_value = 0; float temperature = 0; + Timer t; + + t.start(); + // Read 0-1.0 value for(int i = 0; i < N; i++) { analogin_value += temperature_sensor.read(); + Thread::wait(100); } - // Average 10 sensor values + + t.stop(); + + printf("We did %d averages of temperature in %d ms\r\n", N, t.read_ms()); + + // Average N sensor values analogin_value /= (float) N; temperature = analoginToCelsius(analogin_value); @@ -66,15 +86,6 @@ printf("Temperature: %f Celsius\r\n", temperature); } -float TemperatureController::getTemperature() -{ - float temperature = 0; - - temperature = readSensor(); - - return temperature; -} - float TemperatureController::getOffset(float voltage) { float denominator_voltage, numerator_voltage, ratio, interpolation; @@ -114,9 +125,11 @@ { if(readSensor() < 32.0f) { - heater = 1; + //heater = 1; + printf("Should set heater to 1\r\n"); } else { - heater = 0; + //heater = 0; + printf("Should set heater to 0\r\n"); } } \ No newline at end of file