Tedd OKANO
/
k64f-acc-example
Simplified version for hands-on
Revision 5:8ad6d9a777b4, committed 2019-12-20
- Comitter:
- okano
- Date:
- Fri Dec 20 07:20:44 2019 +0000
- Parent:
- 4:80464da5d880
- Commit message:
- Simplified version
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 80464da5d880 -r 8ad6d9a777b4 main.cpp --- a/main.cpp Wed Oct 16 06:14:39 2019 +0000 +++ b/main.cpp Fri Dec 20 07:20:44 2019 +0000 @@ -3,47 +3,52 @@ * SPDX-License-Identifier: Apache-2.0 */ +/* mbed-fest hands-on session sample 2 + * bare-metal blinky with classic style code + */ + #include "mbed.h" #include "FXOS8700Q.h" -I2C i2c(PTE25, PTE24); -FXOS8700QAccelerometer acc(i2c, FXOS8700CQ_SLAVE_ADDR1); +I2C i2c( PTE25, PTE24 ); +FXOS8700QAccelerometer acc( i2c, FXOS8700CQ_SLAVE_ADDR1 ); -DigitalOut led_x(LED1); -DigitalOut led_y(LED2); -DigitalOut led_z(LED3); +DigitalOut led_x( LED1 ); +DigitalOut led_y( LED2 ); +DigitalOut led_z( LED3 ); int main(void) { - motion_data_counts_t acc_raw; - int16_t raX, raY, raZ; - + float x, y, z; + // 加速度センサーの初期化 acc.enable(); while (true) { + // データの取得 - acc.getAxis(acc_raw); - acc.getX(raX); - acc.getY(raY); - acc.getZ(raZ); + acc.getX( x ); + acc.getY( y ); + acc.getZ( z ); // LED点滅 - if (raX > 0) + if ( x > 0 ) led_x = 1; else led_x = 0; - if (raY > 0) + + if ( y > 0 ) led_y = 1; else led_y = 0; - if (raZ > 0) + + if ( z > 0 ) led_z = 1; else led_z = 0; - // データの出力 - printf("X: %d, Y: %d, Z:%d\n", raX, raY, raZ); - wait(0.5f); + // データの出力(コンソールへ) + printf("X:%6.1f, Y:%6.1f, Z:%6.1f\r\n", x * 90.0, y * 90.0, z * 90.0 ); + wait( 0.5 ); } } \ No newline at end of file