![](/media/cache/profiles/795c7a7a5ec6b460ec00c5841019b9e9.jpg.50x50_q85.jpg)
aaa
Diff: main.cpp
- Revision:
- 3:e7e62f8a974b
- Parent:
- 1:d78c639f6b65
- Child:
- 5:8ad6d9a777b4
--- a/main.cpp Thu Sep 26 12:00:11 2019 +0100 +++ b/main.cpp Wed Oct 16 06:11:36 2019 +0000 @@ -4,16 +4,46 @@ */ #include "mbed.h" +#include "FXOS8700Q.h" -#define WAIT_TIME 500 //msec +I2C i2c(PTE25, PTE24); +FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); -DigitalOut led1(LED1); +DigitalOut led_x(LED1); +DigitalOut led_y(LED2); +DigitalOut led_z(LED3); -int main() +int main(void) { - while (true) - { - led1 = !led1; - wait_ms(WAIT_TIME); + motion_data_counts_t acc_raw; + int16_t raX, raY, raZ; + + // 加速度センサーの初期化 + acc.enable(); + + while (true) { + // データの取得 + acc.getAxis(acc_raw); + acc.getX(raX); + acc.getY(raY); + acc.getZ(raZ); + + // LED点滅 + if (raX > 0) + led_x = 1; + else + led_x = 0; + if (raY > 0) + led_y = 1; + else + led_y = 0; + if (raZ > 0) + led_z = 1; + else + led_z = 0; + + // データの出力 + printf("X: %d, Y: %d, Z:%d\n", raX, raY, raZ); + wait(0.5f); } -} +} \ No newline at end of file