se

Dependencies:   SDFileSystem circular_buffer MPU6050 SoftSerial

source/main.cpp

Committer:
suads
Date:
2018-11-22
Revision:
5:ea629a3fd6c1
Parent:
4:147bbe6f9626

File content as of revision 5:ea629a3fd6c1:

//#include <events/mbed_events.h>
#include <mbed.h>
#include "MPU6050.h"
#include <string>
#include <stdio.h>



DigitalOut led(p25, 1);
MPU6050 mpu6050;
Serial pc(USBTX,USBRX);

int main()
{
    pc.baud(115200);
    pc.printf("START_1\n");
    mpu6050.calibrate(accelBias, gyroBias);
    mpu6050.initialize();
    pc.printf("START_2\n");
    
   
 
 /////////////////////////////////////////////////////////SERIAL////////////////////////////////////////////
    while(0){
        led = 0;
        wait(1);
   if(pc.readable()){
       if(pc.getc()=='.'){
            pc.putc(pc.getc());
            led=1;
          wait(1);
          }
            }
  
        }
       
 /////////////////////////////////////////////////////////SERIAL/////////////////////////////////////////////
 
 /////////////////////////////////////////////////////////MPU6050////////////////////////////////////////////
 
    while(0){
         pc.printf("i am %d\n",mpu6050.getDeviceID());
         wait(1);
        }
       
 /////////////////////////////////////////////////////////MPU6050/////////////////////////////////////////////
 
 
 
 //////////////////////////////////////////////////////////////GET_DATA////////////////////////////////////////////
    while(1){
 
    mpu6050.readAccelData(accelData);
    mpu6050.getAres();
    ax = accelData[0]*aRes  - accelBias[0];
    ay = accelData[1]*aRes  - accelBias[1];
    az = accelData[2]*aRes  - accelBias[2];
    float accelValues[3] = {ax,ay,az};
    mpu6050.readGyroData(gyroData);
    mpu6050.getGres();
    gx = gyroData[0]*gRes - gyroBias[0];
    gy = gyroData[1]*gRes - gyroBias[1];
    gz = gyroData[2]*gRes - gyroBias[2];
    float gyroValues[3] = {gx,gy,gz};
        
    if(pc.readable())
    {
        if(pc.getc()=='.'){
            
            pc.printf("%f, ",gx);
            pc.printf("%f, ",gy);
            pc.printf("%f",gz);
           
        }

    }
    
    }
}