LAURUS / Mbed 2 deprecated Laurus_height

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "LPS25H.h"
00003 
00004 #define FREQUENCY 0.10
00005 
00006 I2C i2c(I2C_SDA, I2C_SCL);
00007  
00008 DigitalOut myled(LED1);
00009 DigitalIn mybutton(USER_BUTTON);
00010  
00011 Serial pc(SERIAL_TX, SERIAL_RX);
00012 
00013 LPS25H lps25h(i2c);
00014 
00015 Ticker timer;
00016 void Int_Timer();
00017 
00018 double pres, temp, h, p0=0.0;
00019 double t;
00020 
00021 int main(){
00022     //pc.printf("Start!\n");
00023     pc.printf("time,pressure,tempreture,height\n");
00024     // Set reference value
00025     int i;
00026     for(i=0; i<10; i++){
00027         p0 += (double)lps25h.pressure()/4096.0;
00028         wait(0.1);
00029     }
00030     p0/=10;
00031 
00032     //(FREQUENCY)s間隔のタイマー割り込み
00033     timer.attach(&Int_Timer, FREQUENCY);
00034     
00035     t = 0.0;
00036     //ボタンで終了
00037     while(1){
00038         if(mybutton==0){
00039             timer.detach();
00040             break;
00041         }
00042         myled=!myled;
00043         wait(0.2);
00044     } 
00045     //pc.printf("Finish!\n");
00046 }
00047  
00048 /** タイマー割り込み **/
00049 void Int_Timer() {
00050     //char buf[50];
00051     pres = (double)lps25h.pressure()/4096.0;
00052     temp = 42.5 + (double)lps25h.temperature()/480.0;
00053     h = (pow((p0/pres),0.1902)-1.0)*(temp+273.15)/0.0065;
00054 
00055     pc.printf("%.1f,%.2f,%.2f,%.2f\n", t, pres, temp, h);
00056     //sprintf(buf, "%.2f,%.2f,%.2f,%.2f\n", t, pres, temp, h);
00057     //fprintf(fp, buf);
00058     //logger.puts(buf);
00059     t += FREQUENCY;
00060 }