Basic example showing how to use the Gyroscope (L3GD20 device) present on DISCO_L476VG board.

Dependencies:   GYRO_DISCO_L476VG BSP_DISCO_L476VG

Committer:
Jerome Coutant
Date:
Wed Nov 20 15:13:34 2019 +0100
Revision:
4:25b2a1150cd0
Parent:
0:5432bdf904f9
Update with CubeL4 V1.14.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:5432bdf904f9 1 #include "mbed.h"
bcostm 0:5432bdf904f9 2 #include "GYRO_DISCO_L476VG.h"
bcostm 0:5432bdf904f9 3
bcostm 0:5432bdf904f9 4 GYRO_DISCO_L476VG gyro;
bcostm 0:5432bdf904f9 5
bcostm 0:5432bdf904f9 6 DigitalOut led1(LED1);
bcostm 0:5432bdf904f9 7
bcostm 0:5432bdf904f9 8 int main()
bcostm 0:5432bdf904f9 9 {
bcostm 0:5432bdf904f9 10 float GyroBuffer[3];
bcostm 0:5432bdf904f9 11
bcostm 0:5432bdf904f9 12 printf("Gyroscope started\n");
bcostm 0:5432bdf904f9 13
bcostm 0:5432bdf904f9 14 while(1) {
bcostm 0:5432bdf904f9 15 // Read Gyroscope values
bcostm 0:5432bdf904f9 16 gyro.GetXYZ(GyroBuffer);
bcostm 0:5432bdf904f9 17 // Display values
bcostm 0:5432bdf904f9 18 printf("X = %f\n", GyroBuffer[0]);
bcostm 0:5432bdf904f9 19 printf("Y = %f\n", GyroBuffer[1]);
bcostm 0:5432bdf904f9 20 printf("Z = %f\n", GyroBuffer[2]);
bcostm 0:5432bdf904f9 21 printf("\033[3A"); // Moves cursor up x lines (x value is between [ and A)
bcostm 0:5432bdf904f9 22 led1 = !led1;
bcostm 0:5432bdf904f9 23 wait(1);
bcostm 0:5432bdf904f9 24 }
bcostm 0:5432bdf904f9 25 }