example

Dependencies:   sgam-lib

main.cpp

Committer:
AndersonIctus
Date:
2019-06-01
Revision:
7:310098916153
Parent:
6:ea945b2ea724
Child:
8:69160f286ed3

File content as of revision 7:310098916153:

#include "mbed.h"
// #include "Grove_temperature.h"
// #include "MPU6050.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

// Sensor de movimento !!!
I2C    i2c(I2C_SDA, I2C_SCL);       // PORTA I2C
MPU6050 mpu(i2c, MPU6050_ADDRESS_AD0_LOW);

// Constantes usadas no sensor de movimento !
int16_t ax, ay, az;
int16_t gx, gy, gz;

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");    

    mpu.initialize();

    bool mpu6050TestResult = mpu.testConnection();
    if(mpu6050TestResult) {
        printf("MPU6050 test passed \r\n");
    } else {
        printf("MPU6050 test failed \r\n");
        printf("FIM \r\n");
        return 0;
    }

    int count = 0;
    float tempValue = 0;
    char buffer_giro[100];
    while(count ++ < 25) {
        // ------------------------------------------------------ //
        mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

        //sabe calibrar o gyroscópio!  
        if ( gz > 150 ) { 
            sprintf(buffer_giro, "Movimentou Z .... gy_z = %d", gz);
        } else if ( gy > 50 ){             
            sprintf(buffer_giro, "Movimentou Y .... gy_y = %d",gy);
        } else if ( gx < -370 ){            
            sprintf(buffer_giro, "Movimentou X .... gy_x = %d",gx);
        } else {
            sprintf(buffer_giro, "Sem movimento!");
        }
        
        // ------------------------------------------------------ //
        tempValue = temp.getTemperature();        
        // Acende o LED quando está acima do valor indicado !!
        if(tempValue > 30.0) {
            led_dig = 1;
        } else {
            led_dig = 0;
        }
        // ------------------------------------------------------ //

        printf("******************* ROLL -> %02d ********************\r\n", count);
        printf("*** Giro -> %-35s ***\r\n", buffer_giro);
        printf("*** (gy_x = %03d; gy_y = %03d; gy_z = %03d)       ***\r\n", gx, gy, gz);
        printf("*** Temperatura -> %02.02f                        ***\r\n", tempValue);
        printf("***************************************************\r\n\r\n");

        wait(2);
    }

    printf("!!!FIM DE LEITURA!!!\r\n");
    return 1;
}
*/

int main(){
    return 1;    
}