kirthiga annamalai
/
LM
gaya
Fork of temp by
main.cpp@0:e035f4506cd7, 2012-08-17 (annotated)
- Committer:
- 4180_1
- Date:
- Fri Aug 17 15:48:22 2012 +0000
- Revision:
- 0:e035f4506cd7
- Child:
- 1:460ecfe930b7
ver 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:e035f4506cd7 | 1 | #include "mbed.h" |
4180_1 | 0:e035f4506cd7 | 2 | |
4180_1 | 0:e035f4506cd7 | 3 | //Print temperature from LM61 analog temperature sensor |
4180_1 | 0:e035f4506cd7 | 4 | |
4180_1 | 0:e035f4506cd7 | 5 | //set p15 to analog input to read LM61 sensor's voltage output |
4180_1 | 0:e035f4506cd7 | 6 | AnalogIn LM61(p15); |
4180_1 | 0:e035f4506cd7 | 7 | |
4180_1 | 0:e035f4506cd7 | 8 | //also setting unused analog input pins to digital outputs reduces A/D noise a bit |
4180_1 | 0:e035f4506cd7 | 9 | //see http://mbed.org/users/chris/notebook/Getting-best-ADC-performance/ |
4180_1 | 0:e035f4506cd7 | 10 | DigitalOut P16(p16); |
4180_1 | 0:e035f4506cd7 | 11 | DigitalOut P17(p17); |
4180_1 | 0:e035f4506cd7 | 12 | DigitalOut P18(p18); |
4180_1 | 0:e035f4506cd7 | 13 | DigitalOut P19(p19); |
4180_1 | 0:e035f4506cd7 | 14 | DigitalOut P20(p20); |
4180_1 | 0:e035f4506cd7 | 15 | |
4180_1 | 0:e035f4506cd7 | 16 | int main() |
4180_1 | 0:e035f4506cd7 | 17 | { |
4180_1 | 0:e035f4506cd7 | 18 | float tempC, tempF; |
4180_1 | 0:e035f4506cd7 | 19 | |
4180_1 | 0:e035f4506cd7 | 20 | while(1) { |
4180_1 | 0:e035f4506cd7 | 21 | //conversion to degrees C - from sensor output voltage per LM61 data sheet |
4180_1 | 0:e035f4506cd7 | 22 | tempC = ((LM61*3.3)-0.600)*100.0; |
4180_1 | 0:e035f4506cd7 | 23 | //convert to degrees F |
4180_1 | 0:e035f4506cd7 | 24 | tempF = (9.0*tempC)/5.0 + 32.0; |
4180_1 | 0:e035f4506cd7 | 25 | //print current temp |
4180_1 | 0:e035f4506cd7 | 26 | printf("%5.2F C %5.2F F \n\r", tempC, tempF); |
4180_1 | 0:e035f4506cd7 | 27 | wait(.5); |
4180_1 | 0:e035f4506cd7 | 28 | } |
4180_1 | 0:e035f4506cd7 | 29 | } |