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.
TemperatureSensor.cpp
00001 #include <TemperatureSensor.h> 00002 #include <math.h> 00003 00004 TemperatureSensor::TemperatureSensor():adc(p20) { 00005 percentOfScale= adc.read(); 00006 } 00007 00008 void TemperatureSensor::measure(void) { 00009 static const float R= 10500.0; 00010 static const float LP= 0.01; 00011 00012 percentOfScale= ((1.0 - LP) * percentOfScale) + (LP * adc.read()); 00013 resistance= (percentOfScale * R) / (1.0 - percentOfScale); 00014 } 00015 00016 float TemperatureSensor::getKelvin(void) { 00017 float x; 00018 00019 // Compute the Steinhard-Hart eqn: 1/t = A + B*ln(r) + C*ln(r)^3 + D*ln(r)^5 00020 static const float A= 1.006389097E-3; 00021 static const float B= 2.425678347E-4; 00022 static const float C= 1.452612422E-7; 00023 00024 x= log(resistance); 00025 return 1.0 / (A + (B * x) + (C * x * x * x)); 00026 } 00027 00028 float TemperatureSensor::getResistance(void) { 00029 return resistance; 00030 } 00031 00032 float TemperatureSensor::getPercentOfScale(void) { 00033 return percentOfScale; 00034 }
Generated on Wed Jul 13 2022 23:42:34 by
1.7.2