mbed-xbee(ATmode/pc対マイコン) ,LPS25HBの統合一段階目。 cmdの初期化が問題となっている。errorがでない。 確かめ付けました(2022/08/10) f
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 00061 char cmd1 = xbee.getc();//cmd共有 00062 int va1 = xbee.readable();//これ1にならないと一向に進まないよ 00063 00064 if(va1==1){//3 //これいいがいは永遠にまつ。 00065 wait_us(1); 00066 //機体の放出後→データを取る 00067 if(cmd1 == 'm'){//4 00068 pc.printf("start\r\n"); 00069 t.start(); 00070 cmd1 = 'a'; 00071 00072 press.attach(&pre, 1.0); 00073 00074 while(1){//4 00075 //if (pc.readable()) xbee.putc(pc.getc()); 00076 if (xbee.readable()) pc.putc(xbee.getc()); 00077 //printf("oo"); 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 //データ(気圧,GPS,地磁気)を取る。 00086 //データの保存を10回行い, 保存する。 00087 00088 /***********************************************************/ 00089 char cmd2 = xbee.getc(); 00090 int va2 = xbee.readable();//これ1にならないと一向に進まないよ 00091 00092 //xbee.printf("%x\r\n",cmd); 00093 00094 if(va2 == 1){//5 00095 wait_us(1); 00096 //機体の着陸後→プログラムを終わらす。 00097 if(cmd2 == 'n'){//5 00098 press.detach(); 00099 pc.printf("end\r\n"); 00100 pc.printf("time = %f",t.read()); 00101 t.stop(); 00102 cmd2 = 'a'; 00103 00104 return 0; 00105 00106 }//5 00107 va2 = 0; 00108 }//5 00109 }//4 00110 }//4 00111 00112 va1 =0; 00113 }//3 00114 }//2 00115 }//1
Generated on Sat Aug 13 2022 11:58:38 by 1.7.2