Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 6:ea945b2ea724, committed 2019-05-21
- Comitter:
- AndersonIctus
- Date:
- Tue May 21 02:51:20 2019 +0000
- Parent:
- 5:e16fe9e301f9
- Child:
- 7:310098916153
- Commit message:
- commit de lib
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue May 21 00:09:41 2019 +0000
+++ b/main.cpp Tue May 21 02:51:20 2019 +0000
@@ -1,5 +1,6 @@
#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)
@@ -7,6 +8,14 @@
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) {
@@ -26,86 +35,56 @@
}
int main () {
- printf("!!!INICIO!!!\r\n");
+ 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;
- while(count ++ < 50) {
- tempValue = temp.getTemperature();
- printf("%2d -> Temperature = %2.2f\r\n", count, tempValue);
+ 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;
}
- wait(1);
+ // ------------------------------------------------------ //
+
+ 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;
}
-
-/**
-#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);
- }
-}
-*/