kirthiga annamalai
/
temp
temp
Fork of LM61 by
main.cpp@1:460ecfe930b7, 2015-01-14 (annotated)
- Committer:
- kirthigaannamalai
- Date:
- Wed Jan 14 06:05:53 2015 +0000
- Revision:
- 1:460ecfe930b7
- Parent:
- 0:e035f4506cd7
slowdown blink rate
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); |
kirthigaannamalai | 1:460ecfe930b7 | 11 | DigitalOut myled(LED1); |
kirthigaannamalai | 1:460ecfe930b7 | 12 | DigitalOut myled2(LED2); |
4180_1 | 0:e035f4506cd7 | 13 | |
4180_1 | 0:e035f4506cd7 | 14 | int main() |
4180_1 | 0:e035f4506cd7 | 15 | { |
4180_1 | 0:e035f4506cd7 | 16 | float tempC, tempF; |
4180_1 | 0:e035f4506cd7 | 17 | |
4180_1 | 0:e035f4506cd7 | 18 | while(1) { |
4180_1 | 0:e035f4506cd7 | 19 | //conversion to degrees C - from sensor output voltage per LM61 data sheet |
4180_1 | 0:e035f4506cd7 | 20 | tempC = ((LM61*3.3)-0.600)*100.0; |
4180_1 | 0:e035f4506cd7 | 21 | //convert to degrees F |
4180_1 | 0:e035f4506cd7 | 22 | tempF = (9.0*tempC)/5.0 + 32.0; |
4180_1 | 0:e035f4506cd7 | 23 | //print current temp |
4180_1 | 0:e035f4506cd7 | 24 | printf("%5.2F C %5.2F F \n\r", tempC, tempF); |
4180_1 | 0:e035f4506cd7 | 25 | wait(.5); |
kirthigaannamalai | 1:460ecfe930b7 | 26 | if(P16>29) |
kirthigaannamalai | 1:460ecfe930b7 | 27 | { |
kirthigaannamalai | 1:460ecfe930b7 | 28 | myled=1; |
kirthigaannamalai | 1:460ecfe930b7 | 29 | myled2=0; |
kirthigaannamalai | 1:460ecfe930b7 | 30 | wait(1.0); |
kirthigaannamalai | 1:460ecfe930b7 | 31 | } |
kirthigaannamalai | 1:460ecfe930b7 | 32 | else |
kirthigaannamalai | 1:460ecfe930b7 | 33 | { |
kirthigaannamalai | 1:460ecfe930b7 | 34 | myled=0; |
kirthigaannamalai | 1:460ecfe930b7 | 35 | myled2=1; |
kirthigaannamalai | 1:460ecfe930b7 | 36 | wait(1.0); |
kirthigaannamalai | 1:460ecfe930b7 | 37 | } |
kirthigaannamalai | 1:460ecfe930b7 | 38 | } |
4180_1 | 0:e035f4506cd7 | 39 | } |