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.
Dependents: HealthCare_Graduation
LM35.cpp
00001 #include "LM35.h" 00002 00003 LM35Therm::LM35Therm(PinName analogPin, float compensation) { 00004 _pAin = new AnalogIn(analogPin); 00005 _calibrate = compensation; 00006 _isFirstRead = true; 00007 } 00008 00009 LM35Therm::~LM35Therm() { 00010 delete _pAin; 00011 } 00012 00013 void LM35Therm::getAverageValue() { 00014 _sumAnalog = 0; 00015 00016 for (uint8_t i = 0; i < SAMPLE_COUNT; i++) { 00017 analogSamples[i] = _pAin->read(); 00018 } 00019 00020 for (uint8_t i = 0; i < SAMPLE_COUNT; i++) { 00021 _sumAnalog = _sumAnalog + analogSamples[i]; 00022 } 00023 00024 averageAnalog = _sumAnalog / SAMPLE_COUNT; 00025 _sumAnalog = 0; 00026 00027 if (_isFirstRead) { 00028 for (uint8_t i = 0; i < SAMPLE_COUNT; i++) { 00029 analogAverageSamples[i] = averageAnalog; 00030 _sumAnalog = _sumAnalog + analogAverageSamples[i]; 00031 } 00032 filtedAvgAnalog = _sumAnalog / SAMPLE_COUNT; 00033 _isFirstRead = false; 00034 } 00035 else { 00036 for (uint8_t i = 0; i < SAMPLE_COUNT - 1; i++) { 00037 analogAverageSamples[i] = analogAverageSamples[i]; 00038 _sumAnalog = _sumAnalog + analogAverageSamples[i]; 00039 } 00040 analogAverageSamples[SAMPLE_COUNT - 1] = averageAnalog; 00041 _sumAnalog = _sumAnalog + analogAverageSamples[SAMPLE_COUNT - 1]; 00042 } 00043 filtedAvgAnalog = _sumAnalog / SAMPLE_COUNT; 00044 } 00045 00046 void LM35Therm::setCompensation(float newCompensation) { 00047 _calibrate = newCompensation; 00048 } 00049 00050 float LM35Therm::LM35Therm::getTempInC() { 00051 _readVoltage = filtedAvgAnalog * 3.3; 00052 float avgVolt = filtedAvgAnalog * _calibrate * 1000.0; 00053 tempInC = avgVolt; 00054 return tempInC; 00055 } 00056 00057 float LM35Therm::LM35Therm::getTempInF() { 00058 tempInF = (9.0 * tempInC)/5.0 + 32.0; 00059 return tempInF; 00060 }
Generated on Sun Jul 31 2022 21:32:44 by
1.7.2