read pressure and temperature from LPS25h.
Dependencies: mbed
main.cpp@1:813b3c3eb644, 2015-04-13 (annotated)
- Committer:
- onaka
- Date:
- Mon Apr 13 12:47:42 2015 +0000
- Revision:
- 1:813b3c3eb644
- Parent:
- 0:955628fdbf95
- Child:
- 3:844fb47ba7a2
config changed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
onaka | 0:955628fdbf95 | 1 | #include "mbed.h" |
onaka | 0:955628fdbf95 | 2 | #include "LPS25H.h" |
onaka | 0:955628fdbf95 | 3 | |
onaka | 0:955628fdbf95 | 4 | I2C i2c(I2C_SDA, I2C_SCL); |
onaka | 0:955628fdbf95 | 5 | |
onaka | 0:955628fdbf95 | 6 | DigitalOut myled(LED1); |
onaka | 0:955628fdbf95 | 7 | |
onaka | 0:955628fdbf95 | 8 | Serial pc(SERIAL_TX, SERIAL_RX); |
onaka | 0:955628fdbf95 | 9 | |
onaka | 0:955628fdbf95 | 10 | LPS25H lps25h(i2c); |
onaka | 0:955628fdbf95 | 11 | |
onaka | 0:955628fdbf95 | 12 | int main(){ |
onaka | 0:955628fdbf95 | 13 | |
onaka | 0:955628fdbf95 | 14 | double p, t, h, p0; |
onaka | 0:955628fdbf95 | 15 | |
onaka | 0:955628fdbf95 | 16 | // Set reference value |
onaka | 0:955628fdbf95 | 17 | p0 = (double)lps25h.pressure()/4096.0; |
onaka | 0:955628fdbf95 | 18 | pc.printf("Set p0 = %7.2fhPa\n", p0); |
onaka | 0:955628fdbf95 | 19 | |
onaka | 0:955628fdbf95 | 20 | while (1) { |
onaka | 0:955628fdbf95 | 21 | // Read pressure & temperature |
onaka | 0:955628fdbf95 | 22 | p = (double)lps25h.pressure()/4096.0; |
onaka | 0:955628fdbf95 | 23 | t = 42.5 + (double)lps25h.temperature()/480.0; |
onaka | 0:955628fdbf95 | 24 | |
onaka | 1:813b3c3eb644 | 25 | // Calculate height |
onaka | 0:955628fdbf95 | 26 | h = (pow((p0/p),0.1902)-1.0)*(t+273.15)/0.0065; |
onaka | 0:955628fdbf95 | 27 | |
onaka | 0:955628fdbf95 | 28 | // Display result |
onaka | 0:955628fdbf95 | 29 | pc.printf("height = %4.1fm, pressure = %7.2fhPa, temperature = %5.2fC\n", h, p, t); |
onaka | 0:955628fdbf95 | 30 | myled = !myled; |
onaka | 0:955628fdbf95 | 31 | wait(1.0); |
onaka | 0:955628fdbf95 | 32 | } |
onaka | 0:955628fdbf95 | 33 | |
onaka | 0:955628fdbf95 | 34 | } |
onaka | 0:955628fdbf95 | 35 | |
onaka | 0:955628fdbf95 | 36 |