test

Dependencies:   MPU6050 ledControl2 mbed

main.cpp

Committer:
dgu
Date:
2018-01-19
Revision:
0:24e3c27078b0

File content as of revision 0:24e3c27078b0:

#include "mbed.h"
#include "MPU6050.h"
#include "ledControl.h"

Serial pc(USBTX, USBRX);  
MPU6050 mpu6050;

Ticker toggler1;

void toggle_led1();
//void toggle_led2();

float pitchAngle = 0;
float rollAngle = 0;
float yawAngle = 0;

int main() 
{
    pc.baud(9600);          // baud rate: 9600
    mpu6050.whoAmI();       // Communication test: WHO_AM_I register reading 
    wait(1);
    mpu6050.calibrate(accelBias,gyroBias);  // Calibrate MPU6050
    pc.printf("Calibration is completed. \r\n");
    wait(0.5);
    mpu6050.init();         // Initialize the sensor
    wait(1);
    pc.printf("MPU6050 is initialized for operation.. \r\n\r\n");
    wait_ms(500);
 
    while(1) 
    {
        mpu6050.complementaryFilter(&pitchAngle, &rollAngle, &yawAngle);
        //pc.printf("%.3f,%.3f,%.3f   \r\n",pitchAngle, rollAngle,yawAngle);
        pc.printf("%.3f,%.3f,%.3f   \r\n",ax, ay,az);
        //wait(0.1);

    }
}

void toggle_led1() {ledToggle(1);}
//void toggle_led2() {ledToggle(2);}