Final1x
Dependencies: GYRO_DISCO_L476VG BSP_DISCO_L476VG COMPASS_DISCO_L476VG
Diff: main.cpp
- Revision:
- 5:f4a35a2a9085
- Parent:
- 0:5432bdf904f9
- Child:
- 6:6df9f66ca6bb
--- a/main.cpp Wed Nov 20 15:13:34 2019 +0100 +++ b/main.cpp Mon Jun 08 17:42:48 2020 +0000 @@ -2,24 +2,57 @@ #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) { - // Read Gyroscope values - gyro.GetXYZ(GyroBuffer); - // Display values - printf("X = %f\n", GyroBuffer[0]); - printf("Y = %f\n", GyroBuffer[1]); - printf("Z = %f\n", GyroBuffer[2]); - printf("\033[3A"); // Moves cursor up x lines (x value is between [ and A) - led1 = !led1; - wait(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; + } } }