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/
main.cpp
- Committer:
- ohtsuka
- Date:
- 2014-09-08
- Revision:
- 7:8407141d1f70
- Parent:
- 6:496f4e967298
- Child:
- 8:505d06bba7b1
File content as of revision 7:8407141d1f70:
#include "mbed.h" #include <math.h> #include "LPS331_I2C.h" //気圧計算用 #define P0 1013.25f //海面気圧(hPa) #define TEMP 20 //気温(度) DigitalOut myled(LED1); DigitalOut JPlow(p5); // p6ピンでLowを検出させるために使用。隣同士(p5,p6)のピンをショートさせるとログ出力停止 DigitalIn JP(p6); LocalFileSystem local("local"); Timer t; LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH); // 気圧センサ int main() { JPlow = 0; JP.mode(PullUp); lps331.setResolution(LPS331_I2C_PRESSURE_AVG_512, LPS331_I2C_TEMP_AVG_128); lps331.setDataRate(LPS331_I2C_DATARATE_7HZ); // 7Hz(1秒間に7回更新) lps331.setActive(true); // 動作開始 FILE *fp = fopen("/local/data.txt", "a"); // 「追記」でファイルを開く fprintf(fp,"BBsat start. **********\r\n"); // fprintf()は、ファイルに文字を出力 fclose(fp); t.start(); while(1) { int ms=0; // リセットからの経過時間(単位:ミリ秒(MilliSecond) float pres=lps331.getPressure(); // 気圧 float temp=lps331.getTemperature(); // 気温 float height; // 高度 //★デバッグ用 pres = 900; height = ( (powf((P0/pres),1/5.257f)-1)*(TEMP+273.15) ) / 0.0065f; printf("height = %5.1f\r\n", height); if(JP==0) { // JPが0(GND)だったら、 break; //whileのループを終了 } 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); // 時刻,気圧,気温を出力 fclose(fp); wait(0.05); // LED点滅 myled = 1; wait(0.05); myled = 0; } }