Sample program to get ambient temperature from MCP9700 sensor
Fork of TempSensor by
main.cpp@0:6dde232b3b3b, 2010-11-23 (annotated)
- Committer:
- todotani
- Date:
- Tue Nov 23 00:46:29 2010 +0000
- Revision:
- 0:6dde232b3b3b
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
todotani | 0:6dde232b3b3b | 1 | #include "mbed.h" |
todotani | 0:6dde232b3b3b | 2 | #include "TextLCD.h" |
todotani | 0:6dde232b3b3b | 3 | #include "LinearTempSensor.h" |
todotani | 0:6dde232b3b3b | 4 | |
todotani | 0:6dde232b3b3b | 5 | TextLCD lcd(p24, p26, p27, p28, p29, p30, TextLCD::LCD16x2); // RS, E, DB4, DB5, DB6, DB7 |
todotani | 0:6dde232b3b3b | 6 | LinearTempSensor sensor(p20); // With default parameters |
todotani | 0:6dde232b3b3b | 7 | //LinearTempSensor sensor(p20, 5, LinearTempSensor::MCP9700); // With option parameters |
todotani | 0:6dde232b3b3b | 8 | |
todotani | 0:6dde232b3b3b | 9 | int main() |
todotani | 0:6dde232b3b3b | 10 | { |
todotani | 0:6dde232b3b3b | 11 | float Vout, Tav, To; |
todotani | 0:6dde232b3b3b | 12 | |
todotani | 0:6dde232b3b3b | 13 | lcd.cls(); |
todotani | 0:6dde232b3b3b | 14 | lcd.printf("TEMP:"); |
todotani | 0:6dde232b3b3b | 15 | |
todotani | 0:6dde232b3b3b | 16 | while(true) |
todotani | 0:6dde232b3b3b | 17 | { |
todotani | 0:6dde232b3b3b | 18 | Vout = sensor.Sense(); // Sample data (read sensor) |
todotani | 0:6dde232b3b3b | 19 | Tav = sensor.GetAverageTemp(); // Calculate average temperature from N samples |
todotani | 0:6dde232b3b3b | 20 | To = sensor.GetLatestTemp(); // Calculate temperature from the latest sample |
todotani | 0:6dde232b3b3b | 21 | |
todotani | 0:6dde232b3b3b | 22 | lcd.locate(5, 0); |
todotani | 0:6dde232b3b3b | 23 | lcd.printf("%4.1f", Tav); |
todotani | 0:6dde232b3b3b | 24 | printf("Vout:%f Tav:%f To:%f\n\r", Vout, Tav, To); // Debug print |
todotani | 0:6dde232b3b3b | 25 | |
todotani | 0:6dde232b3b3b | 26 | wait(2.0); |
todotani | 0:6dde232b3b3b | 27 | } |
todotani | 0:6dde232b3b3b | 28 | } |