4-sensor-acelerometro-giroscopio

Dependencies:   MPU6050

main.cpp

Committer:
thevic16
Date:
2021-07-15
Revision:
0:3637652d1040

File content as of revision 0:3637652d1040:

/* mbed Microcontroller Library
 * Copyright (c) 2019 ARM Limited
 * SPDX-License-Identifier: Apache-2.0
 */

#include "mbed.h"
#include "platform/mbed_thread.h"
#include "MPU6050.h"
#include <math.h>

// Blinking rate in milliseconds
#define BLINKING_RATE_MS                                                    500

MPU6050 mpu1(D2,D4);



int main()
{
    if(mpu1.testConnection() == true){
        //printf("Conectadado exitosamente \n");
    }
    else{
       //printf("Error conexion \n");
    }

    while (true) {
        
        thread_sleep_for(BLINKING_RATE_MS);
        
        //Sensor Aceleracion
        /*
        int x = mpu1.getAcceleroRawX();
        int y = mpu1.getAcceleroRawY();
        int z = mpu1.getAcceleroRawZ();
        
        int magAce =  sqrt(x*x + y*y + z*z);
        printf("%d",magAce);
        printf("\r \n");
        */
        
        
        printf(" X: %d",mpu1.getAcceleroRawX());
        printf(" | ");
        printf(" Y: %d",mpu1.getAcceleroRawY());
        printf(" | ");
        printf(" Z: %d",mpu1.getAcceleroRawZ());
        printf("\r \n");
        
        
        /*
        printf("Sensor Giroscopio:\n");
        printf("En el eje X:%d \n",mpu1.getGyroRawX());
        printf("En el eje Y:%d \n",mpu1.getGyroRawY());
        printf("En el eje Z:%d \n",mpu1.getGyroRawZ());
        printf("\n");
        */
    }
}