
Read Temperature from Temperature sensor and display on Serial
Dependencies: C12832 LM75B mbed
main.cpp@1:1c42336484a8, 2015-10-10 (annotated)
- Committer:
- dwijaybane
- Date:
- Sat Oct 10 07:05:07 2015 +0000
- Revision:
- 1:1c42336484a8
- Parent:
- 0:6dcecb339af3
comments updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dwijaybane | 1:1c42336484a8 | 1 | #include "mbed.h" // Basic Library required for onchip peripherals |
dwijaybane | 1:1c42336484a8 | 2 | #include "LM75B.h" // Library for LM75B I2C based Temperature sensor |
dwijaybane | 0:6dcecb339af3 | 3 | |
dwijaybane | 1:1c42336484a8 | 4 | /* Create Objects */ |
dwijaybane | 1:1c42336484a8 | 5 | LM75B tmp(p28,p27); // Initialize I2C pins for Temperature Sensor |
dwijaybane | 1:1c42336484a8 | 6 | Serial pc(USBTX, USBRX); // Map USBTX and USBRX pins as serial out and in |
dwijaybane | 0:6dcecb339af3 | 7 | |
dwijaybane | 1:1c42336484a8 | 8 | /* Main Program */ |
dwijaybane | 0:6dcecb339af3 | 9 | int main () |
dwijaybane | 0:6dcecb339af3 | 10 | { |
dwijaybane | 0:6dcecb339af3 | 11 | float board_temp; |
dwijaybane | 0:6dcecb339af3 | 12 | |
dwijaybane | 1:1c42336484a8 | 13 | /** |
dwijaybane | 1:1c42336484a8 | 14 | * Configure Terminal at 9600 8N1 configuration |
dwijaybane | 1:1c42336484a8 | 15 | * In linux COM port would be /dev/ttyACM0 |
dwijaybane | 1:1c42336484a8 | 16 | * or to find out use "dmesg" command |
dwijaybane | 1:1c42336484a8 | 17 | */ |
dwijaybane | 0:6dcecb339af3 | 18 | while (1) { |
dwijaybane | 1:1c42336484a8 | 19 | board_temp = tmp; // read temperature |
dwijaybane | 1:1c42336484a8 | 20 | pc.printf("Board Temperature = %.2f\n\r",board_temp); // Display temperature on Terminal |
dwijaybane | 1:1c42336484a8 | 21 | wait(1.0); // 1 sec delay |
dwijaybane | 0:6dcecb339af3 | 22 | } |
dwijaybane | 0:6dcecb339af3 | 23 | } |