Final1x

Dependencies:   GYRO_DISCO_L476VG mbed BSP_DISCO_L476VG COMPASS_DISCO_L476VG

Committer:
gr91
Date:
Mon Jun 08 17:42:48 2020 +0000
Revision:
5:f4a35a2a9085
Parent:
0:5432bdf904f9
Child:
6:6df9f66ca6bb
V2

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;
gr91 5:f4a35a2a9085 5 Serial pc(SERIAL_TX, SERIAL_RX,115200);
gr91 5:f4a35a2a9085 6 Ticker ticker;
bcostm 0:5432bdf904f9 7 DigitalOut led1(LED1);
gr91 5:f4a35a2a9085 8 volatile bool flag=0;
gr91 5:f4a35a2a9085 9 float psig=0;
gr91 5:f4a35a2a9085 10 float gyro_zero(void)
gr91 5:f4a35a2a9085 11 {
gr91 5:f4a35a2a9085 12 const int NN=100000;
gr91 5:f4a35a2a9085 13 float GyroBuffer[3];
gr91 5:f4a35a2a9085 14 float gy_off=0;
gr91 5:f4a35a2a9085 15 for(int i=0; i<NN; i++)
gr91 5:f4a35a2a9085 16 {
gr91 5:f4a35a2a9085 17 gyro.GetXYZ(GyroBuffer);
gr91 5:f4a35a2a9085 18 gy_off=gy_off+GyroBuffer[1]/NN;
gr91 5:f4a35a2a9085 19
gr91 5:f4a35a2a9085 20 }
gr91 5:f4a35a2a9085 21 return(gy_off);
gr91 5:f4a35a2a9085 22 }
gr91 5:f4a35a2a9085 23 void mesure(void)
gr91 5:f4a35a2a9085 24 {
gr91 5:f4a35a2a9085 25 flag=1;
gr91 5:f4a35a2a9085 26 }
bcostm 0:5432bdf904f9 27
bcostm 0:5432bdf904f9 28 int main()
bcostm 0:5432bdf904f9 29 {
bcostm 0:5432bdf904f9 30 float GyroBuffer[3];
gr91 5:f4a35a2a9085 31
bcostm 0:5432bdf904f9 32 printf("Gyroscope started\n");
gr91 5:f4a35a2a9085 33 ticker.attach(&mesure,0.01);
gr91 5:f4a35a2a9085 34 unsigned char cpt=0;
gr91 5:f4a35a2a9085 35 float gyoff=gyro_zero();
bcostm 0:5432bdf904f9 36 while(1) {
gr91 5:f4a35a2a9085 37 if(flag) {
gr91 5:f4a35a2a9085 38
gr91 5:f4a35a2a9085 39 // Read Gyroscope values
gr91 5:f4a35a2a9085 40 gyro.GetXYZ(GyroBuffer);
gr91 5:f4a35a2a9085 41 psig=psig+(GyroBuffer[1]-gyoff)*0.01/1000;
gr91 5:f4a35a2a9085 42
gr91 5:f4a35a2a9085 43 // Display values
gr91 5:f4a35a2a9085 44 //printf("X = %8.1f \n", GyroBuffer[0]);
gr91 5:f4a35a2a9085 45 // printf("Y = %8.1f \n", GyroBuffer[1]);
gr91 5:f4a35a2a9085 46 //printf("Z = %8.1f \n", GyroBuffer[2]);
gr91 5:f4a35a2a9085 47 // printf("\033[3A"); // Moves cursor up x lines (x value is between [ and A)
gr91 5:f4a35a2a9085 48 if(cpt==9) {
gr91 5:f4a35a2a9085 49 cpt=0;
gr91 5:f4a35a2a9085 50 led1 = !led1;
gr91 5:f4a35a2a9085 51 //pc.printf("$%f;\n",GyroBuffer[1]);
gr91 5:f4a35a2a9085 52 pc.printf("$%f;\n",psig);
gr91 5:f4a35a2a9085 53 }
gr91 5:f4a35a2a9085 54 cpt++;
gr91 5:f4a35a2a9085 55 flag=0;
gr91 5:f4a35a2a9085 56 }
bcostm 0:5432bdf904f9 57 }
bcostm 0:5432bdf904f9 58 }