Equipo7 LabMicros / Mbed 2 deprecated I2C_3A

Dependencies:   mbed MMA8451Q

Revision:
1:936a1850d885
Parent:
0:a9e068e17f41
Child:
3:777d4daea16d
--- a/main.cpp	Mon Apr 25 05:54:46 2022 +0000
+++ b/main.cpp	Mon Apr 25 18:46:01 2022 +0000
@@ -1,4 +1,4 @@
-//CÓDIGO 1-A
+//CÓDIGO 3-A
 
 #include "mbed.h"
 #include "MMA8451Q.h"
@@ -8,17 +8,15 @@
 #define MMA8451_I2C_ADDRESS (0x1d << 1)
 Serial pc(USBTX, USBRX);
 
-
 #define BUFFER_SIZE 50
 #define SLAVE_ADDR 0xA0
 I2C master(I2C_SDA, I2C_SCL);
 
 
- 
 int main(void)
 {
     master.frequency (100000);
-    pc.printf("\x1b[2J");       //CLEAR
+    pc.printf("\x1b[2J");      //CLEAR
     pc.printf("\r");           //Mueve cursor al origen
     pc.printf("MASTER\r\n");
     
@@ -35,20 +33,24 @@
             pc.printf("CONECTADO %s\r\n", buf);
     }
     
-    float x, y, z;
+    float x, y, z; // Aceleracion en cada eje
     
     while (true) {
         
-        x = abs(acc.getAccX());
+        x = abs(acc.getAccX()); // Obtener aceleracion en cada eje
         y = abs(acc.getAccY());
         z = abs(acc.getAccZ());
-        
-        rled = 1.0f - x;
+    
+        wait(1);
+    
+        rled = 1.0f - x; //Encender LED interno
         gled = 1.0f - y;
         bled = 1.0f - z;
         
-        sprintf(buf, "%1.2f, %1.2f, %1.2f", x, y, z);
+        //pc.printf("X: %1.1f, Y: %1.1f, Z: %1.1f\r\n", x, y, z);
+        sprintf(buf, "%1.1f, %1.1f, %1.1f", x, y, z);
         pc.printf("%s\r\n", buf);
+        
         if (master.write(SLAVE_ADDR, buf, BUFFER_SIZE) == 0) 
         {
             wait(0.2);
@@ -62,7 +64,5 @@
             wait(0.2);
             pc.printf("Written to slave: %s\r\n", buf);
         } 
-        
-        
     }
 } 
\ No newline at end of file