read pressure and temperature from LPS25h.

Dependencies:   mbed

Revision:
0:955628fdbf95
Child:
1:813b3c3eb644
diff -r 000000000000 -r 955628fdbf95 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Apr 13 06:39:17 2015 +0000
@@ -0,0 +1,36 @@
+#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);
+    }
+ 
+}
+ 
+