Minh Nguyen / MPU6050

Files at this revision

API Documentation at this revision

Comitter:
khaiminhvn
Date:
Wed Mar 10 20:53:54 2021 +0000
Parent:
13:23c9db5753c8
Commit message:
Changes to I2C input

Changed in this revision

MPU6050.cpp Show annotated file Show diff for this revision Revisions of this file
MPU6050.h Show annotated file Show diff for this revision Revisions of this file
--- a/MPU6050.cpp	Mon Feb 15 21:48:30 2021 +0000
+++ b/MPU6050.cpp	Wed Mar 10 20:53:54 2021 +0000
@@ -3,7 +3,8 @@
  */
 #include "MPU6050.h"
 
-MPU6050::MPU6050(PinName sda, PinName scl) : connection(sda, scl) {
+MPU6050::MPU6050(I2C *i2cIn){
+    connection = i2cIn;
     this->setSleepMode(false);
     
     //Initializations:
@@ -21,19 +22,19 @@
     temp[0]=address;
     temp[1]=data;
     
-    connection.write(MPU6050_ADDRESS * 2,temp,2);
+    connection->write(MPU6050_ADDRESS * 2,temp,2);
 }
 
 char MPU6050::read(char address) {
     char retval;
-    connection.write(MPU6050_ADDRESS * 2, &address, 1, true);
-    connection.read(MPU6050_ADDRESS * 2, &retval, 1);
+    connection->write(MPU6050_ADDRESS * 2, &address, 1, true);
+    connection->read(MPU6050_ADDRESS * 2, &retval, 1);
     return retval;
 }
 
 void MPU6050::read(char address, char *data, int length) {
-    connection.write(MPU6050_ADDRESS * 2, &address, 1, true);
-    connection.read(MPU6050_ADDRESS * 2, data, length);
+    connection->write(MPU6050_ADDRESS * 2, &address, 1, true);
+    connection->read(MPU6050_ADDRESS * 2, data, length);
 }
 
 void MPU6050::setSleepMode(bool state) {
--- a/MPU6050.h	Mon Feb 15 21:48:30 2021 +0000
+++ b/MPU6050.h	Wed Mar 10 20:53:54 2021 +0000
@@ -103,7 +103,7 @@
      * @param sda - mbed pin to use for the SDA I2C line.
      * @param scl - mbed pin to use for the SCL I2C line.
      */
-     MPU6050(PinName sda, PinName scl);
+     MPU6050(I2C *i2cIn);
      
 
      /**
@@ -321,7 +321,7 @@
      
      private:
 
-     I2C connection;
+     I2C *connection;
      char currentAcceleroRange;
      char currentGyroRange;
      float alpha;