Anderson Cunha
/
example_smart-grid
example
main.cpp
- Committer:
- AndersonIctus
- Date:
- 2019-05-21
- Revision:
- 5:e16fe9e301f9
- Parent:
- 4:60f2a8b3727c
- Child:
- 6:ea945b2ea724
File content as of revision 5:e16fe9e301f9:
#include "mbed.h" #include "Grove_temperature.h" DigitalOut led1 (LED1); // LED 1 de 3 DO BOARD DigitalOut led_dig(D6); // LED 1 da porta Digital 6 (A placa tem D6 e D8) Grove_temperature temp(A1); // Deve ser ligado na Porta ANALOGICA 1 Serial pc(USBTX, USBRX); // SAIDA SERIAL PADRÃO void rodarLed() { int count = 0; while(count ++ < 10) { led1 = 1; wait(0.4); led1 = 0; wait(0.2); } led1 = 0; } void buss_ligth() { led_dig = 1; wait(0.3); led_dig = 0; } int main () { printf("!!!INICIO!!!\r\n"); int count = 0; float tempValue = 0; while(count ++ < 50) { tempValue = temp.getTemperature(); printf("%2d -> Temperature = %2.2f\r\n", count, tempValue); // Acende o LED quando está acima do valor indicado !! if(tempValue > 30.0) { led_dig = 1; } else { led_dig = 0; } wait(1); } 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); } } */