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.
Revision 3:970c2fa6ef3f, committed 2019-10-25
- 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 |
--- 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)
--- 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