Demo of the IKS01A1 - accelerometers

Dependencies:   X_NUCLEO_IKS01A1-f255a2c75ecb-14ddc33717d5

Committer:
noutram
Date:
Tue Jun 26 16:50:53 2018 +0000
Revision:
0:1882e480b627
Demo of the IKS01A1 - accelerometers;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noutram 0:1882e480b627 1 #include "mbed.h"
noutram 0:1882e480b627 2 #include "x_nucleo_iks01a1.h"
noutram 0:1882e480b627 3
noutram 0:1882e480b627 4 //Onboard LED for indication purposes
noutram 0:1882e480b627 5 DigitalOut led1(LED1);
noutram 0:1882e480b627 6
noutram 0:1882e480b627 7 // Inertial & Environmental expansion board singleton instance
noutram 0:1882e480b627 8 static X_NUCLEO_IKS01A1 *expansion_board = X_NUCLEO_IKS01A1::Instance();
noutram 0:1882e480b627 9 int32_t xyz[3];
noutram 0:1882e480b627 10
noutram 0:1882e480b627 11 // main() runs in its own thread in the OS
noutram 0:1882e480b627 12 int main() {
noutram 0:1882e480b627 13
noutram 0:1882e480b627 14 MotionSensor *acc = expansion_board->GetAccelerometer();
noutram 0:1882e480b627 15
noutram 0:1882e480b627 16 while (true) {
noutram 0:1882e480b627 17 //Indicator
noutram 0:1882e480b627 18 led1 = !led1;
noutram 0:1882e480b627 19 wait(0.5);
noutram 0:1882e480b627 20
noutram 0:1882e480b627 21 //This is NOT interrupt safe
noutram 0:1882e480b627 22 acc->Get_X_Axes(xyz);
noutram 0:1882e480b627 23
noutram 0:1882e480b627 24 //Display on the terminal
noutram 0:1882e480b627 25 int32_t x = xyz[0];
noutram 0:1882e480b627 26 int32_t y = xyz[1];
noutram 0:1882e480b627 27 int32_t z = xyz[2];
noutram 0:1882e480b627 28 printf("x=%d\ty=%d\tz=%d\n\r",x,y,z);
noutram 0:1882e480b627 29 }
noutram 0:1882e480b627 30 }
noutram 0:1882e480b627 31