mbed-xbee(ATmode/pc対マイコン) ,LPS35HBの統合一段階目。 cmdの初期化が問題となっている。errorがでない。
Dependencies: mbed LPS25HB_I2C
main.cpp
00001 #include "mbed.h" 00002 #include "LPS.h" 00003 00004 Timer t; 00005 00006 Serial pc(USBTX, USBRX); // tx, rx 00007 Serial xbee(D1, D0); // tx, rx 00008 00009 ///////////////////////////// 00010 I2C i2c(D4,D5); 00011 LPS ps(i2c); 00012 /////////////////////////// 00013 00014 Ticker press; 00015 00016 void pre() { 00017 if (!ps.init()){//2 00018 printf("Failed to autodetect pressure sensor!\r\n"); 00019 while (1); 00020 }//2 00021 00022 ps.enableDefault(); 00023 00024 float pressure = ps.readPressureMillibars(); 00025 float altitude = ps.pressureToAltitudeMeters(pressure); 00026 float temperature = ps.readTemperatureC(); 00027 pc.printf("p:%.2f\t mbar\ta:%.2f m\tt:%.2f deg C\r\n",pressure,altitude,temperature); 00028 00029 } 00030 00031 00032 00033 int main() {//1 00034 pc.printf("settig start\r\n"); 00035 xbee.printf("settig start\r\n"); 00036 00037 /////////////////////////////// 00038 /*if (!ps.init()){//2 00039 printf("Failed to autodetect pressure sensor!\r\n"); 00040 while (1); 00041 }//2 00042 ps.enableDefault();*/ 00043 /////////////////////////////// 00044 00045 /**************************************************************/ 00046 00047 00048 //ここに気圧の標高の較正とGPSの接続を行う。 00049 00050 00051 /**************************************************************/ 00052 00053 pc.printf("begin\r\n"); 00054 xbee.printf("begin\r\n"); 00055 00056 for (;;) {//2 00057 00058 //if (pc.readable()) xbee.putc(pc.getc()); 00059 if (xbee.readable()) pc.putc(xbee.getc()); 00060 wait_us(1); 00061 00062 char cmd1 = xbee.getc();//cmd共有 00063 00064 //機体の放出後→データを取る 00065 if(cmd1 == 'm'){//3 00066 pc.printf("start\r\n"); 00067 t.start(); 00068 cmd1 = 0; 00069 00070 press.attach(&pre, 1.0); 00071 00072 while(1){//4 00073 //if (pc.readable()) xbee.putc(pc.getc()); 00074 if (xbee.readable()) pc.putc(xbee.getc()); 00075 //printf("oo"); 00076 wait_us(1); 00077 00078 /***********************************************************/ 00079 ////////////////////////////////////// 00080 //float pressure = ps.readPressureMillibars(); 00081 //float altitude = ps.pressureToAltitudeMeters(pressure); 00082 //float temperature = ps.readTemperatureC(); 00083 //pc.printf("p:%.2f\t mbar\ta:%.2f m\tt:%.2f deg C\r\n",pressure,altitude,temperature); 00084 00085 ////////////////////////////////////// 00086 00087 //データ(気圧,GPS,地磁気)を取る。 00088 //データの保存を10回行い, 保存する。 00089 00090 00091 /***********************************************************/ 00092 char cmd2 = xbee.getc();//共有化 00093 //xbee.printf("%x\r\n",cmd); 00094 00095 00096 //機体の着陸後→プログラムを終わらす。 00097 if(cmd2 == 'n'){//5 00098 pc.printf("end\r\n"); 00099 pc.printf("time = %f",t.read()); 00100 t.stop(); 00101 cmd2 = 0; 00102 00103 return 0; 00104 00105 }//5 00106 00107 }//4 00108 00109 00110 }//3 00111 }//2 00112 }//1
Generated on Tue Aug 9 2022 14:11:37 by 1.7.2