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
Diff: TemperatureController.cpp
- Revision:
- 0:dab140a197e0
- Child:
- 1:eb527bc93b62
diff -r 000000000000 -r dab140a197e0 TemperatureController.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TemperatureController.cpp Fri Jun 03 14:24:25 2016 +0000 @@ -0,0 +1,60 @@ +#include "TemperatureController.h" + +#include "stdio.h" + +AnalogIn temperature_sensor(p20); + +TemperatureController::TemperatureController() +{ + printf("Initiate Temperature Controller\r\n"); +} + +// Function reads sensor values and averages N sensor values +float TemperatureController::readSensor() +{ + float analogin_value; + float temperature; + + // Read 0-1.0 value + for(int i = 0; i < N; i++) + { + analogin_value += temperature_sensor.read(); + } + // Average 10 sensor values + analogin_value /= (float) N; + + temperature = analoginToCelsius(analogin_value); + + return temperature; +} + +// Function converts average sensor value to ppt +float TemperatureController::analoginToCelsius(float analogin_value) +{ + float voltage; + float rt, logrt; + float temperature; + + // Convert average sensor value to value with range 0-5.0v + voltage = analogin_value * 3.3f * (5.0f/3.0f) + 0.45f; + + // Calcuate R_T + rt = (15000.0f * voltage) / (4.8f - voltage); + + logrt = log(rt); + temperature = 1.0 / (0.00102119 + (0.000222468 * logrt) + (0.000000133342 * logrt*logrt*logrt)); + + temperature = temperature - 273.15; + + return temperature; +} + +// Function prints temperature sensor value in celsius +void TemperatureController::displayCelsius() +{ + float temperature; + + temperature = readSensor(); + + printf("Temperature: %f Celsius\r\n", temperature); +} \ No newline at end of file