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.
main.cpp
- Committer:
- yzakizon
- Date:
- 2013-11-06
- Revision:
- 0:83dfc83e48bf
File content as of revision 0:83dfc83e48bf:
#include "mbed.h" DigitalOut myled(LED1); Serial pc(USBTX, USBRX); AnalogIn tempPin(p15); float tempTotal; uint32_t tempDiv; #define MAX_TEMP_AVG 10 void sampleTemperature(); void sampleTemperatures(); void resetTemperatureSamples(); float getAvgTemperature(); void sampleTemperature() { tempTotal += tempPin; //we use 3.3V from VOUT tempDiv++; } void sampleTemperatures() { for(int i=0;i<MAX_TEMP_AVG;i++) { sampleTemperature(); wait(0.1); } } void resetTemperatureSamples() { tempTotal = 0.0; tempDiv = 0; } float getAvgTemperature() { /* Temperature calculations is (VOut - V0)/Tc * VOut = V out from sensor * V0 = Voltage on 0 Celcius, 500mv for MCP9700 * Tc = Temperatur constant, 10mV/C */ float tempAvg = (((tempTotal*3300)/(float)tempDiv)-500.0)/10.0; return tempAvg; } int main() { tempDiv = 0; pc.printf("MBED ready..\r\n"); sampleTemperatures(); pc.printf("Temp: %.2f.\r\n",getAvgTemperature()); while(1) { sampleTemperature(); myled = 1; wait(0.5); myled = 0; wait(0.5); if (tempDiv > MAX_TEMP_AVG) { pc.printf("Temp: %.2f.\r\n",getAvgTemperature()); resetTemperatureSamples(); } } }