LinkNode_BMP180
Dependencies: BLE_API BMP180 mbed nRF51822
Fork of BMP180_example by
main.cpp@3:b66abd88f595, 2016-01-28 (annotated)
- Committer:
- helloqi
- Date:
- Thu Jan 28 01:38:38 2016 +0000
- Revision:
- 3:b66abd88f595
- Parent:
- 0:f03b6a07c4ba
- Child:
- 4:e039f39e789d
2016.01.28
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kgills | 0:f03b6a07c4ba | 1 | #include <stdio.h> |
kgills | 0:f03b6a07c4ba | 2 | #include "mbed.h" |
kgills | 0:f03b6a07c4ba | 3 | #include "BMP180.h" |
kgills | 0:f03b6a07c4ba | 4 | |
helloqi | 3:b66abd88f595 | 5 | Serial pc(P0_23,P0_25); |
helloqi | 3:b66abd88f595 | 6 | DigitalOut led(P0_20); |
helloqi | 3:b66abd88f595 | 7 | I2C i2c(P0_17, P0_18); |
kgills | 0:f03b6a07c4ba | 8 | BMP180 bmp180(&i2c); |
kgills | 0:f03b6a07c4ba | 9 | |
helloqi | 3:b66abd88f595 | 10 | int main(void) |
helloqi | 3:b66abd88f595 | 11 | { |
helloqi | 3:b66abd88f595 | 12 | led=0; |
helloqi | 3:b66abd88f595 | 13 | while(1) |
helloqi | 3:b66abd88f595 | 14 | { |
helloqi | 3:b66abd88f595 | 15 | if (bmp180.init() != 0) |
helloqi | 3:b66abd88f595 | 16 | { |
kgills | 0:f03b6a07c4ba | 17 | printf("Error communicating with BMP180\n"); |
helloqi | 3:b66abd88f595 | 18 | } |
helloqi | 3:b66abd88f595 | 19 | else |
helloqi | 3:b66abd88f595 | 20 | { |
kgills | 0:f03b6a07c4ba | 21 | printf("Initialized BMP180\n"); |
kgills | 0:f03b6a07c4ba | 22 | break; |
kgills | 0:f03b6a07c4ba | 23 | } |
kgills | 0:f03b6a07c4ba | 24 | wait(1); |
kgills | 0:f03b6a07c4ba | 25 | } |
kgills | 0:f03b6a07c4ba | 26 | |
helloqi | 3:b66abd88f595 | 27 | while(1) |
helloqi | 3:b66abd88f595 | 28 | { |
kgills | 0:f03b6a07c4ba | 29 | bmp180.startTemperature(); |
kgills | 0:f03b6a07c4ba | 30 | wait_ms(5); // Wait for conversion to complete |
kgills | 0:f03b6a07c4ba | 31 | float temp; |
helloqi | 3:b66abd88f595 | 32 | if(bmp180.getTemperature(&temp) != 0) |
helloqi | 3:b66abd88f595 | 33 | { |
kgills | 0:f03b6a07c4ba | 34 | printf("Error getting temperature\n"); |
kgills | 0:f03b6a07c4ba | 35 | continue; |
kgills | 0:f03b6a07c4ba | 36 | } |
kgills | 0:f03b6a07c4ba | 37 | bmp180.startPressure(BMP180::ULTRA_LOW_POWER); |
kgills | 0:f03b6a07c4ba | 38 | wait_ms(10); // Wait for conversion to complete |
kgills | 0:f03b6a07c4ba | 39 | int pressure; |
helloqi | 3:b66abd88f595 | 40 | if(bmp180.getPressure(&pressure) != 0) |
helloqi | 3:b66abd88f595 | 41 | { |
kgills | 0:f03b6a07c4ba | 42 | printf("Error getting pressure\n"); |
kgills | 0:f03b6a07c4ba | 43 | continue; |
kgills | 0:f03b6a07c4ba | 44 | } |
kgills | 0:f03b6a07c4ba | 45 | |
kgills | 0:f03b6a07c4ba | 46 | printf("Pressure = %d Pa Temperature = %f C\n", pressure, temp); |
kgills | 0:f03b6a07c4ba | 47 | wait(1); |
kgills | 0:f03b6a07c4ba | 48 | } |
kgills | 0:f03b6a07c4ba | 49 | } |