Demo of the IKS01A1 - accelerometers
Dependencies: X_NUCLEO_IKS01A1-f255a2c75ecb-14ddc33717d5
Diff: main.cpp
- Revision:
- 0:1882e480b627
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jun 26 16:50:53 2018 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" +#include "x_nucleo_iks01a1.h" + +//Onboard LED for indication purposes +DigitalOut led1(LED1); + + // Inertial & Environmental expansion board singleton instance +static X_NUCLEO_IKS01A1 *expansion_board = X_NUCLEO_IKS01A1::Instance(); +int32_t xyz[3]; + +// main() runs in its own thread in the OS +int main() { + + MotionSensor *acc = expansion_board->GetAccelerometer(); + + while (true) { + //Indicator + led1 = !led1; + wait(0.5); + + //This is NOT interrupt safe + acc->Get_X_Axes(xyz); + + //Display on the terminal + int32_t x = xyz[0]; + int32_t y = xyz[1]; + int32_t z = xyz[2]; + printf("x=%d\ty=%d\tz=%d\n\r",x,y,z); + } +} +