Maiko Matsumoto
/
BLE_WallbotBLE_Challenge2_2
0611
Fork of BLE_WallbotBLE_Challenge2 by
Revision 4:53eceb750885, committed 2018-06-11
- Comitter:
- mmmmmmmmma
- Date:
- Mon Jun 11 04:55:58 2018 +0000
- Parent:
- 3:f707552ec50a
- Commit message:
- 0611
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f707552ec50a -r 53eceb750885 main.cpp --- a/main.cpp Sun Jun 03 07:04:34 2018 +0000 +++ b/main.cpp Mon Jun 11 04:55:58 2018 +0000 @@ -9,10 +9,8 @@ BLEDevice ble; MPU6050 mpu(I2C_SDA, I2C_SCL); +Serial pc(USBTX, USBRX); -#if DBG -Serial pc(USBTX, USBRX); -#endif /* LEDs for indication: */ DigitalOut ModeLed(P0_19); DigitalOut ConnectStateLed(P0_18); @@ -366,6 +364,72 @@ /*! @brief Program entry point */ + +//#define CONN_INTERVAL 25 /**< connection interval 250ms; in multiples of 0.125ms. (durationInMillis * 1000) / UNIT_0_625_MS; */ +//#define CONN_SUP_TIMEOUT 8000 /**< Connection supervisory timeout (6 seconds); in multiples of 0.125ms. */ +//#define SLAVE_LATENCY 0 +#define TICKER_INTERVAL 2.0f + +// ・MPU6050から値を取得 +// ・ループ実行されている関数 +void updateValue(void){ + // 値を格納する用の配列、変数 + float acData[3]; + float gyData[3]; + + //加速度を取得 + Timer acTimer; + acTimer.start(); + mpu.getAccelero(acData); //加速度を取得 acDataに格納 + acTimer.stop(); +// at = acTimer.read_ms(); + acTimer.reset(); + + //ジャイロを取得 + Timer gyTimer; + gyTimer.start(); + mpu.getGyro(gyData); //ジャイロの値(角加速度)を取得 gyDataに格納 + gyTimer.stop(); +// gt = gyTimer.read_ms(); + gyTimer.reset(); + + //floatの値を合計5桁、小数点以下3桁の形でPCへ送信 + pc.printf("%5.3f:%5.3f:%5.3f:%5.3f:%5.3f:%5.3f \n", acData[0], acData[1], acData[2],gyData[0],gyData[1],gyData[2]); +} + +int test() +{ + + ///180601 MPU6050センサの初期化処理 + mpu.initialize(); +// mpu.setAcceleroRange(MPU6050_ACCELERO_RANGE_8G); //加速度センサ 計測レンジ設定(今回は2Gか4Gがよさそう) + mpu.setAcceleroRange(MPU6050_ACCELERO_RANGE_2G); +// mpu.setGyroRange(MPU6050_GYRO_RANGE_1000); //ジャイロセンサ 計測レンジ設定(ここも250か500がよさそう(そんなに早く回転しないので)) + mpu.setGyroRange(MPU6050_GYRO_RANGE_250); + ///180601 + + if( mpu.testConnection() ){ + // pc.printf("mpu test:OK\n\r"); + }else{ + // pc.printf("mpu test:NG\n\r"); + } + + float ticker_ms = (TICKER_INTERVAL / 100.0f); + Ticker ticker; + ticker.attach(periodicCallback, ticker_ms);//0.02f //.2f-sec + + pc.printf("Start!! \n"); + + while(true) { + left = 1.0; + right = 1.0; + // wait(5); + updateValue(); + wait(0.5); + } +} + + /**************************************************************************/ int main(void) { @@ -437,7 +501,7 @@ { bValue = 1; line_mode = 1; - line(); + test(); line_mode = 0; bValue = 0; }