Anderson Cunha
/
example_smart-grid
example
Diff: main.cpp
- Revision:
- 5:e16fe9e301f9
- Parent:
- 4:60f2a8b3727c
- Child:
- 6:ea945b2ea724
--- a/main.cpp Mon May 20 20:59:29 2019 -0300 +++ b/main.cpp Tue May 21 00:09:41 2019 +0000 @@ -46,3 +46,66 @@ printf("!!!FIM DE LEITURA!!!\r\n"); return 1; } + +/** +#include "mbed.h" +#include "MPU6050.h" + +DigitalOut myled(LED1); +Serial pc(USBTX, USBRX); +I2C i2c(I2C_SDA, I2C_SCL); +MPU6050 mpu(i2c); + +int16_t ax, ay, az; +int16_t gx, gy, gz; + +int main() +{ + pc.printf("MPU6050 test\r\n"); + pc.printf("MPU6050 initialize\r\n"); + + mpu.initialize(); + + pc.printf("MPU6050 testConnection \r\n"); + + bool mpu6050TestResult = mpu.testConnection(); + if(mpu6050TestResult) { + pc.printf("MPU6050 test passed \r\n"); + } else { + pc.printf("MPU6050 test failed \r\n"); + pc.printf("FIM \r\n"); + return 0; + } + + while(1) { + wait(2); + mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); + //writing current accelerometer and gyro position + pc.printf("-----------------\r\n"); + pc.printf("## Verificando: \r\n"); + //pc.printf("ac_x = %d; ac_y = %d; ac_z = %d\r\n",ax,ay,az); + //pc.printf("gy_x = %d; gy_y = %d; gy_z = %d\r\n",gx,gy,gz); + //pc.printf("## Rotation\r\n"); + //mpu.getRotation(&gx, &gy, &gz); + //pc.printf("gy_x = %d; gy_y = %d; gy_z = %d\r\n",gx,gy,gz); + + //sabe calibrar o gyroscópio! + if ( gz > 150 ){ + pc.printf("-> Movimentou ....\r\n"); + pc.printf("gy_z = %d\r\n",gz); + + } else if ( gy > 50 ){ + pc.printf("-> Movimentou ....\r\n"); + pc.printf("gy_y = %d \r\n",gy); + + } else if ( gx < -370 ){ + pc.printf("gy_x = %d \r\n",gx); + pc.printf("-> Movimentou ....\r\n"); + + } else { + pc.printf("-> Sem movimento!\r\n"); + } + pc.printf("gy_x = %d; gy_y = %d; gy_z = %d\r\n",gx,gy,gz); + } +} +*/