Alfredo Oliveira / Mbed 2 deprecated LM35WorkingCode

Dependencies:   mbed TextLCD

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /**********************************************************************************************************/
00002 /* ATTENTION: You have to put a 10uF electrolict capacitor between the ground and signal terminals of LM35*/
00003 /**********************************************************************************************************/
00004 #include "mbed.h"
00005 #include "TextLCD.h"
00006 
00007 AnalogIn LM35(PA_6);
00008 TextLCD lcd(PA_12,PA_11, PB_6, PB_5, PB_4, PB_3);
00009 Serial pc(PA_9, PA_10);    //Create an object of Serial Class PA_9=RX, PA_10=TX no FTDI
00010 
00011 /*TextLCD lcd(p21,p22,p23,p24,p25,p26);*/
00012 
00013 int main()
00014 {
00015  double tempC,tempF,avg;//,a[49];
00016  int i;
00017  unsigned short a[99];
00018  while(1)
00019  {
00020  
00021 avg=0;
00022 for(i=0;i<99 ;i++)
00023 {
00024 a[i]=LM35.read_u16();
00025 wait(.02);
00026 }
00027 for(i=0;i<99;i++)
00028 {
00029 avg=avg+(a[i]/100);
00030 }
00031 
00032 
00033 tempC=(((avg*3.3)/65535)*100);//3.685503686
00034 
00035 
00036 //tempF=(9.0*tempC)/5.0 + 32.0;
00037 
00038 lcd.locate(0,0);
00039 //lcd.printf("  Temperature   ");
00040 lcd.locate(0,1);
00041 lcd.printf("%.2f \n %.0f",tempC,avg);
00042 pc.printf("%.2f \n\r",tempC);/*This line is to monitoring de temp values on a Terminal*/
00043 wait(.5);      
00044     }
00045  }