xiugai

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lant19
Date:
Fri Oct 25 02:12:02 2019 +0000
Parent:
2:73237ebf0640
Commit message:
with address

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 73237ebf0640 -r 970c2fa6ef3f PCA9685.cpp
--- a/PCA9685.cpp	Thu Oct 24 08:21:43 2019 +0000
+++ b/PCA9685.cpp	Fri Oct 25 02:12:02 2019 +0000
@@ -4,7 +4,8 @@
 //定义引脚与地址
 void PCA9685::begin(void)//初始化
 {
-    reset();
+    reset(0x80);
+    reset(0x82);
 }
 
 void PCA9685::frequencyI2C(int freq)//初始化
@@ -27,11 +28,13 @@
     return rtn;
 }
 
-void PCA9685::reset(void)//复位
+void PCA9685::reset(int addr4)//复位
 {
+     _i2caddr=addr4;
     write8(PCA9685_MODE1, 0x0);
 }
-void PCA9685::setPrescale(uint8_t prescale) {    
+void PCA9685::setPrescale(uint8_t prescale,int addr2) {    
+    _i2caddr=addr2;
     uint8_t oldmode = read8(PCA9685_MODE1);
     uint8_t newmode = (oldmode&0x7F) | 0x10; // sleep
     write8(PCA9685_MODE1, newmode); // go to sleep
@@ -41,13 +44,14 @@
     wait_ms(5);
     write8(PCA9685_MODE1, oldmode | 0xa1);
 }
-void PCA9685::setPWMFreq(float freq) //设置频率
+void PCA9685::setPWMFreq(float freq,int addr3) //设置频率
 {
+    _i2caddr=addr3;
     float prescaleval = 25000000;
     prescaleval /= 4096;
     prescaleval /= freq;
     uint8_t prescale = floor(prescaleval  + 0.5) - 1;
-    setPrescale(prescale);
+    setPrescale(prescale,addr3);
 }
 
 void PCA9685::setPWM(uint8_t num, uint16_t on, uint16_t off,int addr)
diff -r 73237ebf0640 -r 970c2fa6ef3f PCA9685.h
--- a/PCA9685.h	Thu Oct 24 08:21:43 2019 +0000
+++ b/PCA9685.h	Fri Oct 25 02:12:02 2019 +0000
@@ -77,17 +77,17 @@
 class PCA9685
 {
 public:
-    PCA9685(PinName sda, PinName scl);//定义pca9685 地址为1+A5+A4+A3+A2+A1+A0+rw rw写为0 读为1
+    PCA9685(PinName sda, PinName scl);//定义pca9685 地址为1+A5+A4+A3+A2+A1+A0+rw rw写为0 读为1 10000010  0x82
     void frequencyI2C(int freq);
     void begin(void); //初始化
-    void reset(void); //复位
-    void setPrescale(uint8_t prescale);//设置预缩放
+    void reset(int addr4); //复位
+    void setPrescale(uint8_t prescale,int addr2);//设置预缩放
     /** set prescale
      *
      *  @param prescale: set scale for the PWM frequency
      *
      */
-    void setPWMFreq(float freq);//设置PWM频率 单位hz
+    void setPWMFreq(float freq,int addr3);//设置PWM频率 单位hz
     /** Set frequency
       *
       * @param frequency in Hz