Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 3:e7e62f8a974b
- Parent:
- 1:d78c639f6b65
- Child:
- 5:90b5419be471
--- 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