acc + gyro LSM6DSL

Dependencies:   LSM6DSL mbed

Committer:
RichieHard
Date:
Sat Jan 27 13:56:33 2018 +0000
Revision:
0:c8f53c487a49
no comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RichieHard 0:c8f53c487a49 1 #include "mbed.h"
RichieHard 0:c8f53c487a49 2 #include "LSM6DSLSensor.h"
RichieHard 0:c8f53c487a49 3
RichieHard 0:c8f53c487a49 4 int main() {
RichieHard 0:c8f53c487a49 5 uint8_t id;
RichieHard 0:c8f53c487a49 6 int32_t axes[3];
RichieHard 0:c8f53c487a49 7 DevI2C *dev_i2c = new DevI2C(D14, D15);
RichieHard 0:c8f53c487a49 8 LSM6DSLSensor *acc_gyro = new LSM6DSLSensor(dev_i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_LOW, A2, A3);
RichieHard 0:c8f53c487a49 9
RichieHard 0:c8f53c487a49 10 acc_gyro->enable_x();
RichieHard 0:c8f53c487a49 11 acc_gyro->enable_g();
RichieHard 0:c8f53c487a49 12
RichieHard 0:c8f53c487a49 13 printf("\r\nLSM6DSL example\r\n");
RichieHard 0:c8f53c487a49 14
RichieHard 0:c8f53c487a49 15 acc_gyro->read_id(&id);
RichieHard 0:c8f53c487a49 16 printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id);
RichieHard 0:c8f53c487a49 17
RichieHard 0:c8f53c487a49 18 while(1) {
RichieHard 0:c8f53c487a49 19 acc_gyro->get_x_axes(axes);
RichieHard 0:c8f53c487a49 20 printf("LSM6DSL [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
RichieHard 0:c8f53c487a49 21
RichieHard 0:c8f53c487a49 22 acc_gyro->get_g_axes(axes);
RichieHard 0:c8f53c487a49 23 printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]);
RichieHard 0:c8f53c487a49 24 wait(0.2); // 200 ms
RichieHard 0:c8f53c487a49 25 }
RichieHard 0:c8f53c487a49 26 }