This program is for Cansat made with BreadBoard which have pressure sensor LPS331. This program is based on http://mbed.org/users/nyamfg/code/LPS331_HelloWorld/
Diff: main.cpp
- Revision:
- 11:3342540c22d8
- Parent:
- 10:40521f3084ba
- Child:
- 12:6b5035346d43
--- a/main.cpp Wed Sep 10 04:34:42 2014 +0000 +++ b/main.cpp Fri Sep 19 09:39:03 2014 +0000 @@ -17,7 +17,7 @@ //地面との相対高度算出用 #define GROUND_AVE_NUM 10 -float ground_height=0; +float ground_alti=0; LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH); // 気圧センサ @@ -42,19 +42,19 @@ // 地面の高度を求める for(i=0;i<GROUND_AVE_NUM;i++) { pres = lps331.getPressure(); // 気圧 - ground_height += lps331.getAltitude(P0, TEMP, pres); + ground_alti += lps331.getAltitude(P0, TEMP, pres); wait(1/7); } - ground_height = ground_height / GROUND_AVE_NUM; + ground_alti = ground_alti / GROUND_AVE_NUM; while(1) { int ms=0; // リセットからの経過時間(単位:ミリ秒(MilliSecond) - float height; // 高度 + float altitude; // 高度 pres=lps331.getPressure(); // 気圧 temp=lps331.getTemperature(); // 気温 // 高度算出 - height = lps331.getAltitude(P0, TEMP, pres); + altitude = lps331.getAltitude(P0, TEMP, pres); if(JP==0) { // JPが0(GND)だったら、 break; //whileのループを終了 @@ -63,11 +63,11 @@ ms = t.read_ms(); //現在時刻を取得 FILE *fp = fopen("/local/data.txt", "a"); - fprintf(fp, "%10d,%6.2f,%4.1f %5.1f \r\n", ms, pres, temp, height); // 時刻,気圧,気温,高度を出力 - printf( "%10d,%6.2f,%4.1f,Ground:%5.1f Height:%5.1f Diff%5.1f \r\n", ms, pres, temp, ground_height, height, height-ground_height); + fprintf(fp, "%10d,%6.2f,%4.1f %5.1f \r\n", ms, pres, temp, altitude); // 時刻,気圧,気温,高度を出力 + printf( "%10d,%6.2f,%4.1f,Ground:%5.1f altitude:%5.1f Diff%5.1f \r\n", ms, pres, temp, ground_alti, altitude, altitude-ground_alti); fclose(fp); - telem.printf("%5.1f\n", height-ground_height); // 高度を出力 + telem.printf("%5.1f\n", altitude-ground_alti); // 高度を出力 wait(0.05); // LED点滅 myled = 1; wait(0.05);