xiugai

Dependencies:   mbed

Revision:
3:970c2fa6ef3f
Parent:
2:73237ebf0640
--- 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)