Final1x

Dependencies:   GYRO_DISCO_L476VG BSP_DISCO_L476VG COMPASS_DISCO_L476VG

main.cpp

Committer:
gr91
Date:
2020-06-08
Revision:
5:f4a35a2a9085
Parent:
0:5432bdf904f9
Child:
6:6df9f66ca6bb

File content as of revision 5:f4a35a2a9085:

#include "mbed.h"
#include "GYRO_DISCO_L476VG.h"

GYRO_DISCO_L476VG gyro;
Serial pc(SERIAL_TX, SERIAL_RX,115200);
Ticker ticker;
DigitalOut led1(LED1);
volatile bool flag=0;
float psig=0;
float gyro_zero(void)
{
    const int NN=100000;
    float GyroBuffer[3];
    float gy_off=0;
    for(int i=0; i<NN; i++)
      {
        gyro.GetXYZ(GyroBuffer);
        gy_off=gy_off+GyroBuffer[1]/NN;
        
    }
    return(gy_off);
}
void mesure(void)
{
    flag=1;
}

int main()
{
    float GyroBuffer[3];

    printf("Gyroscope started\n");
    ticker.attach(&mesure,0.01);
    unsigned char cpt=0;
    float gyoff=gyro_zero();
    while(1) {
        if(flag) {

            // Read Gyroscope values
            gyro.GetXYZ(GyroBuffer);
            psig=psig+(GyroBuffer[1]-gyoff)*0.01/1000;
            
            // Display values
            //printf("X = %8.1f  \n", GyroBuffer[0]);
            // printf("Y = %8.1f   \n", GyroBuffer[1]);
            //printf("Z = %8.1f  \n", GyroBuffer[2]);
            // printf("\033[3A"); // Moves cursor up x lines (x value is between [ and A)
            if(cpt==9) {
                cpt=0;
                led1 = !led1;
                //pc.printf("$%f;\n",GyroBuffer[1]);
                pc.printf("$%f;\n",psig);
            }
            cpt++;
            flag=0;
        }
    }
}