PCA9685 library

Dependents:   s-rov-firmware DISCO-F746NG_rtos_test

Files at this revision

API Documentation at this revision

Comitter:
YJ_Kim
Date:
Thu Jan 26 17:04:46 2017 +0000
Parent:
1:7e071acc57b1
Commit message:
Change i2c object to pointer

Changed in this revision

pca9685.cpp Show annotated file Show diff for this revision Revisions of this file
pca9685.h Show annotated file Show diff for this revision Revisions of this file
diff -r 7e071acc57b1 -r 5c8802f876f8 pca9685.cpp
--- a/pca9685.cpp	Mon Jan 16 13:00:49 2017 +0000
+++ b/pca9685.cpp	Thu Jan 26 17:04:46 2017 +0000
@@ -1,7 +1,7 @@
 #include "mbed.h"
 #include "pca9685.h"
 
-PCA9685::PCA9685(uint8_t i2c_addr, I2C i2c_object, float freq):
+PCA9685::PCA9685(uint8_t i2c_addr, I2C* i2c_object, float freq):
     PCA9685_ADDR(i2c_addr << 1),
     frequency(freq),
     i2c(i2c_object)
@@ -51,7 +51,7 @@
     cmd[2] = on / 256;
     cmd[3] = off % 256;
     cmd[4] = off / 256;    
-    i2c.write(PCA9685_ADDR, cmd, 5);   
+    i2c->write(PCA9685_ADDR, cmd, 5);   
 }
 
 void PCA9685::set_pwm_duty(uint8_t num, float duty){
@@ -68,12 +68,12 @@
     char cmd[2];
     cmd[0] = reg;
     cmd[1] = msg;
-    i2c.write(PCA9685_ADDR, cmd, 2);
+    i2c->write(PCA9685_ADDR, cmd, 2);
 }
 
 char PCA9685::read_8(uint8_t reg){
     char cmd = reg;
-    i2c.write(PCA9685_ADDR, &cmd, 1);
-    i2c.read(PCA9685_ADDR, &cmd, 1);
+    i2c->write(PCA9685_ADDR, &cmd, 1);
+    i2c->read(PCA9685_ADDR, &cmd, 1);
     return cmd;    
 }
\ No newline at end of file
diff -r 7e071acc57b1 -r 5c8802f876f8 pca9685.h
--- a/pca9685.h	Mon Jan 16 13:00:49 2017 +0000
+++ b/pca9685.h	Thu Jan 26 17:04:46 2017 +0000
@@ -11,7 +11,7 @@
 
 class PCA9685{
     public:
-        PCA9685(uint8_t i2c_addr, I2C i2c_object, float freq); 
+        PCA9685(uint8_t i2c_addr, I2C* i2c_object, float freq); 
         void reset(void);
         void init(void);
         void set_pwm_frequency(float freq);
@@ -24,7 +24,7 @@
     private:
         uint8_t PCA9685_ADDR;
         float frequency;
-        I2C i2c;
+        I2C* i2c;
     
 };