victor gomez
/
4-sensor-acelerometro-giroscopio
4-sensor-acelerometro-giroscopio
main.cpp@0:3637652d1040, 2021-07-15 (annotated)
- Committer:
- thevic16
- Date:
- Thu Jul 15 20:37:26 2021 +0000
- Revision:
- 0:3637652d1040
sensor acelerometro y giroscopio;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thevic16 | 0:3637652d1040 | 1 | /* mbed Microcontroller Library |
thevic16 | 0:3637652d1040 | 2 | * Copyright (c) 2019 ARM Limited |
thevic16 | 0:3637652d1040 | 3 | * SPDX-License-Identifier: Apache-2.0 |
thevic16 | 0:3637652d1040 | 4 | */ |
thevic16 | 0:3637652d1040 | 5 | |
thevic16 | 0:3637652d1040 | 6 | #include "mbed.h" |
thevic16 | 0:3637652d1040 | 7 | #include "platform/mbed_thread.h" |
thevic16 | 0:3637652d1040 | 8 | #include "MPU6050.h" |
thevic16 | 0:3637652d1040 | 9 | #include <math.h> |
thevic16 | 0:3637652d1040 | 10 | |
thevic16 | 0:3637652d1040 | 11 | // Blinking rate in milliseconds |
thevic16 | 0:3637652d1040 | 12 | #define BLINKING_RATE_MS 500 |
thevic16 | 0:3637652d1040 | 13 | |
thevic16 | 0:3637652d1040 | 14 | MPU6050 mpu1(D2,D4); |
thevic16 | 0:3637652d1040 | 15 | |
thevic16 | 0:3637652d1040 | 16 | |
thevic16 | 0:3637652d1040 | 17 | |
thevic16 | 0:3637652d1040 | 18 | int main() |
thevic16 | 0:3637652d1040 | 19 | { |
thevic16 | 0:3637652d1040 | 20 | if(mpu1.testConnection() == true){ |
thevic16 | 0:3637652d1040 | 21 | //printf("Conectadado exitosamente \n"); |
thevic16 | 0:3637652d1040 | 22 | } |
thevic16 | 0:3637652d1040 | 23 | else{ |
thevic16 | 0:3637652d1040 | 24 | //printf("Error conexion \n"); |
thevic16 | 0:3637652d1040 | 25 | } |
thevic16 | 0:3637652d1040 | 26 | |
thevic16 | 0:3637652d1040 | 27 | while (true) { |
thevic16 | 0:3637652d1040 | 28 | |
thevic16 | 0:3637652d1040 | 29 | thread_sleep_for(BLINKING_RATE_MS); |
thevic16 | 0:3637652d1040 | 30 | |
thevic16 | 0:3637652d1040 | 31 | //Sensor Aceleracion |
thevic16 | 0:3637652d1040 | 32 | /* |
thevic16 | 0:3637652d1040 | 33 | int x = mpu1.getAcceleroRawX(); |
thevic16 | 0:3637652d1040 | 34 | int y = mpu1.getAcceleroRawY(); |
thevic16 | 0:3637652d1040 | 35 | int z = mpu1.getAcceleroRawZ(); |
thevic16 | 0:3637652d1040 | 36 | |
thevic16 | 0:3637652d1040 | 37 | int magAce = sqrt(x*x + y*y + z*z); |
thevic16 | 0:3637652d1040 | 38 | printf("%d",magAce); |
thevic16 | 0:3637652d1040 | 39 | printf("\r \n"); |
thevic16 | 0:3637652d1040 | 40 | */ |
thevic16 | 0:3637652d1040 | 41 | |
thevic16 | 0:3637652d1040 | 42 | |
thevic16 | 0:3637652d1040 | 43 | printf(" X: %d",mpu1.getAcceleroRawX()); |
thevic16 | 0:3637652d1040 | 44 | printf(" | "); |
thevic16 | 0:3637652d1040 | 45 | printf(" Y: %d",mpu1.getAcceleroRawY()); |
thevic16 | 0:3637652d1040 | 46 | printf(" | "); |
thevic16 | 0:3637652d1040 | 47 | printf(" Z: %d",mpu1.getAcceleroRawZ()); |
thevic16 | 0:3637652d1040 | 48 | printf("\r \n"); |
thevic16 | 0:3637652d1040 | 49 | |
thevic16 | 0:3637652d1040 | 50 | |
thevic16 | 0:3637652d1040 | 51 | /* |
thevic16 | 0:3637652d1040 | 52 | printf("Sensor Giroscopio:\n"); |
thevic16 | 0:3637652d1040 | 53 | printf("En el eje X:%d \n",mpu1.getGyroRawX()); |
thevic16 | 0:3637652d1040 | 54 | printf("En el eje Y:%d \n",mpu1.getGyroRawY()); |
thevic16 | 0:3637652d1040 | 55 | printf("En el eje Z:%d \n",mpu1.getGyroRawZ()); |
thevic16 | 0:3637652d1040 | 56 | printf("\n"); |
thevic16 | 0:3637652d1040 | 57 | */ |
thevic16 | 0:3637652d1040 | 58 | } |
thevic16 | 0:3637652d1040 | 59 | } |