read pressure and temperature from LPS25h.
Dependencies: mbed
Revision 3:844fb47ba7a2, committed 2015-05-10
- Comitter:
- onaka
- Date:
- Sun May 10 07:00:39 2015 +0000
- Parent:
- 2:0c2bb6fe6885
- Commit message:
- revision 3
Changed in this revision
LPS25H/LPS25H.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/LPS25H/LPS25H.cpp Mon Apr 13 12:54:45 2015 +0000 +++ b/LPS25H/LPS25H.cpp Sun May 10 07:00:39 2015 +0000 @@ -77,9 +77,9 @@ void LPS25H::init() { // Resolution config - put(LPS25H_RES_CONF, 0x05); + put(LPS25H_RES_CONF, 0x0A); // FIFO 4samples moving average - put(LPS25H_FIFO_CTRL, 0xC3); + put(LPS25H_FIFO_CTRL, 0xCF); // FIFO Enable put(LPS25H_CTRL_REG2, 0x40); // Power ON Cycle=12.5Hz
--- a/main.cpp Mon Apr 13 12:54:45 2015 +0000 +++ b/main.cpp Sun May 10 07:00:39 2015 +0000 @@ -1,36 +1,60 @@ #include "mbed.h" #include "LPS25H.h" +#define FREQUENCY 0.10 + I2C i2c(I2C_SDA, I2C_SCL); DigitalOut myled(LED1); +DigitalIn mybutton(USER_BUTTON); Serial pc(SERIAL_TX, SERIAL_RX); LPS25H lps25h(i2c); +Ticker timer; +void Int_Timer(); + +double pres, temp, h, p0=0.0; +double t; + int main(){ - - double p, t, h, p0; - + //pc.printf("Start!\n"); + pc.printf("time,pressure,tempreture,height\n"); // 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 height - 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); + int i; + for(i=0; i<10; i++){ + p0 += (double)lps25h.pressure()/4096.0; + wait(0.1); } - + p0/=10; + + //(FREQUENCY)s間隔のタイマー割り込み + timer.attach(&Int_Timer, FREQUENCY); + + t = 0.0; + //ボタンで終了 + while(1){ + if(mybutton==0){ + timer.detach(); + break; + } + myled=!myled; + wait(0.2); + } + //pc.printf("Finish!\n"); } +/** タイマー割り込み **/ +void Int_Timer() { + //char buf[50]; + pres = (double)lps25h.pressure()/4096.0; + temp = 42.5 + (double)lps25h.temperature()/480.0; + h = (pow((p0/pres),0.1902)-1.0)*(temp+273.15)/0.0065; + pc.printf("%.1f,%.2f,%.2f,%.2f\n", t, pres, temp, h); + //sprintf(buf, "%.2f,%.2f,%.2f,%.2f\n", t, pres, temp, h); + //fprintf(fp, buf); + //logger.puts(buf); + t += FREQUENCY; +}