kirthiga annamalai / Mbed 2 deprecated LM35

Dependencies:   mbed

Fork of LM61 by jim hamblen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 //Print temperature from LM61 analog temperature sensor
00004 
00005 //set p15 to analog input to read LM61 sensor's voltage output
00006 AnalogIn LM61(p15);
00007 
00008 //also setting unused analog input pins to digital outputs reduces A/D noise a bit
00009 //see http://mbed.org/users/chris/notebook/Getting-best-ADC-performance/
00010 DigitalOut P16(p16);
00011 DigitalOut myled(LED1);
00012 DigitalOut myled2(LED2);
00013 
00014 
00015 int main()
00016 {
00017     float tempC, tempF;
00018 
00019     while(1) {
00020         //conversion to degrees C - from sensor output voltage per LM61 data sheet
00021         tempC = ((LM61*3.3)-0.600)*100.0;
00022         //convert to degrees F
00023         tempF = (9.0*tempC)/5.0 + 32.0;
00024         //print current temp
00025         printf("%5.2F C %5.2F F \n\r", tempC, tempF);
00026         wait(.5);
00027         if(tempF=75)
00028          {
00029         myled = 1;
00030         myled2=0;
00031         wait(0.5);
00032         }
00033         else
00034          {
00035          myled = 0;
00036         myled2=1;
00037         wait(0.5);
00038         }
00039     }
00040 }