Yamaguchi Atsushi / Mbed 2 deprecated l3gd20

Dependencies:   mbed

Revision:
2:0eff70bb95df
Parent:
1:04b7521f737d
--- a/main.cpp	Mon Dec 06 06:40:40 2021 +0000
+++ b/main.cpp	Sat Dec 18 15:49:18 2021 +0000
@@ -1,10 +1,11 @@
 # include<mbed.h>
-
+ 
 I2C i2c(D4, D5);//sda,scl
 Serial pc(USBTX,USBRX);
-
-void main() 
+ 
+int main() 
 {
+    while(1){
     /*
     // Create I2C bus
     int file;
@@ -32,7 +33,7 @@
     config[1] = 0x30;
     i2c.write(addr, config, 2);
     wait(1);
-
+ 
     // Read 6 bytes of data
     // lsb first
     // Read xGyro lsb data from register(0x28)
@@ -45,61 +46,61 @@
         exit(1);
     }
     char data_0 = data[0];
-
+ 
     // Read xGyro msb data from register(0x29)
     reg[0] = 0x29;
     i2c.write(addr, reg, 1);
     i2c.read(addr, data, 1);
     char data_1 = data[0];
-
+ 
     // Read yGyro lsb data from register(0x2A)
     reg[0] = 0x2A;
     i2c.write(addr, reg, 1);
     i2c.read(addr, data, 1);
     char data_2 = data[0];
-
+ 
     // Read yGyro msb data from register(0x2B)
     reg[0] = 0x2B;
     i2c.write(addr, reg, 1);
     i2c.read(addr, data, 1);
     char data_3 = data[0];
-
+ 
     // Read zGyro lsb data from register(0x2C)
     reg[0] = 0x2C;
     i2c.write(addr, reg, 1);
     i2c.read(addr, data, 1);
     char data_4 = data[0];
-
+ 
     // Read zGyro msb data from register(0x2D)
     reg[0] = 0x2D;
     i2c.write(addr, reg, 1);
     i2c.read(addr, data, 1);
     char data_5 = data[0];
-
+ 
     // Convert the data
     int xGyro = (data_1 * 256 + data_0);
     if(xGyro > 32767)
     {
         xGyro -= 65536;
     }
-
+ 
     int yGyro = (data_3 * 256 + data_2);
     if(yGyro > 32767)
     {
         yGyro -= 65536;
     }
-
+ 
     int zGyro = (data_5 * 256 + data_4);
     if(zGyro > 32767)
     {
     zGyro -= 65536;
     }
-
+ 
     // Output data to screen
-    while(1){
-    printf("Rotation in X-Axis : %d \n", xGyro);
-    printf("Rotation in Y-Axis : %d \n", yGyro);
-    printf("Rotation in Z-Axis : %d \n", zGyro);
+
+    pc.printf("Rotation in X-Axis : %d \n\r", xGyro*0.00875);
+    pc.printf("Rotation in Y-Axis : %d \n\r", yGyro*0.00875);
+    pc.printf("Rotation in Z-Axis : %d \n\r", zGyro*0.00875);
     wait(0.5);
         }