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-07-24
- Revision:
- 5:f2944e456618
- Parent:
- 4:4c01d79dd741
File content as of revision 5:f2944e456618:
#include "mbed.h" #include "LPS331_I2C.h" DigitalOut myled(LED1); DigitalIn JP(p6); LocalFileSystem local("local"); Timer t; LPS331_I2C lps331(p9, p10, LPS331_I2C_SA0_HIGH); // 気圧センサ int main() { char id; printf("start BBsat\r\n"); JP.mode(PullUp); id = lps331.whoami(); printf("id = %x\r\n", id); 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"); // 「追記」でファイルを開く if(fp==NULL) { printf("fopen error.\r\n"); } 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(); // 気温 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\r\n", ms, pres, temp); // 時刻,気圧,気温を出力 fclose(fp); wait(0.05); // LED点滅 myled = 1; wait(0.05); myled = 0; } }