read pressure and temperature from LPS25h.
Dependencies: mbed
main.cpp
- Committer:
- onaka
- Date:
- 2015-04-13
- Revision:
- 0:955628fdbf95
- Child:
- 1:813b3c3eb644
File content as of revision 0:955628fdbf95:
#include "mbed.h" #include "LPS25H.h" I2C i2c(I2C_SDA, I2C_SCL); DigitalOut myled(LED1); Serial pc(SERIAL_TX, SERIAL_RX); LPS25H lps25h(i2c); int main(){ double p, t, h, p0; // Set reference value p0 = (double)lps25h.pressure()/4096.0; pc.printf("Set p0 = %7.2fhPa\n", p0); while (1) { // Read pressure & temperature p = (double)lps25h.pressure()/4096.0; t = 42.5 + (double)lps25h.temperature()/480.0; // Calculate altitude h = (pow((p0/p),0.1902)-1.0)*(t+273.15)/0.0065; // Display result pc.printf("height = %4.1fm, pressure = %7.2fhPa, temperature = %5.2fC\n", h, p, t); myled = !myled; wait(1.0); } }