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.
Diff: main.cpp
- Revision:
- 1:04b7521f737d
- Parent:
- 0:950c605f154f
- Child:
- 2:0eff70bb95df
--- a/main.cpp	Thu Dec 02 01:55:51 2021 +0000
+++ b/main.cpp	Mon Dec 06 06:40:40 2021 +0000
@@ -1,40 +1,45 @@
 # include<mbed.h>
 
-I2CSlave slave(D9, D10);
+I2C i2c(D4, D5);//sda,scl
+Serial pc(USBTX,USBRX);
 
 void main() 
 {
+    /*
     // Create I2C bus
     int file;
+    //ここから下6行はいらないかも
     char *bus = "/dev/i2c-1";
     if((file = open(bus, O_RDWR)) < 0) 
     {
         printf("Failed to open the bus. \n");
         exit(1);
     }
+    
     // Get I2C device, L3GD20 I2C address is 0x6A(106)
    // ioctl(file, I2C_SLAVE, 0x6A);
-    slave.address(0x6A);
+    slave.address(0x6A);    //1101010のことやと思うからSA0をGNDにつなげばいいと思う
     int i = slave.receive();
-
+*/
+    const int addr = 0x6A;
     // Enable X, Y, Z-Axis and disable Power down mode(0x0F)
     char config[2] = {0};
     config[0] = 0x20;
     config[1] = 0x0F;
-    write(file, config, 2);
+    i2c.write(addr, config, 2);
     // Full scale range, 2000 dps(0x30)
     config[0] = 0x23;
     config[1] = 0x30;
-    write(file, config, 2);
+    i2c.write(addr, config, 2);
     wait(1);
 
     // Read 6 bytes of data
     // lsb first
     // Read xGyro lsb data from register(0x28)
     char reg[1] = {0x28};
-    write(file, reg, 1);
+    i2c.write(addr, reg, 1);
     char data[1] = {0};
-    if(read(file, data, 1) != 1)
+    if(i2c.read(addr, data, 1) != 1)
     {
         printf("Error : Input/Output Error \n");
         exit(1);
@@ -43,32 +48,32 @@
 
     // Read xGyro msb data from register(0x29)
     reg[0] = 0x29;
-    write(file, reg, 1);
-    read(file, data, 1);
+    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;
-    write(file, reg, 1);
-    read(file, data, 1);
+    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;
-    write(file, reg, 1);
-    read(file, data, 1);
+    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;
-    write(file, reg, 1);
-    read(file, data, 1);
+    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;
-    write(file, reg, 1);
-    read(file, data, 1);
+    i2c.write(addr, reg, 1);
+    i2c.read(addr, data, 1);
     char data_5 = data[0];
 
     // Convert the data
@@ -91,7 +96,11 @@
     }
 
     // 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);
+    wait(0.5);
+        }
+    
 }
\ No newline at end of file