33
33
/* !
34
34
* @brief Instantiates a new PCA9685 PWM driver chip with the I2C address on a
35
35
* TwoWire interface
36
+ * @param addr The 7-bit I2C address to locate this chip, default is 0x40
36
37
* @param i2c A pointer to a 'Wire' compatible object that we'll use to
37
38
* communicate with
38
- * @param addr The 7-bit I2C address to locate this chip, default is 0x40
39
39
*/
40
- Adafruit_PWMServoDriver::Adafruit_PWMServoDriver (TwoWire *i2c, uint8_t addr ) {
40
+ Adafruit_PWMServoDriver::Adafruit_PWMServoDriver (uint8_t addr, TwoWire *i2c ) {
41
41
_i2c = i2c;
42
42
_i2caddr = addr;
43
43
}
@@ -46,7 +46,7 @@ Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(TwoWire *i2c, uint8_t addr) {
46
46
* @brief Setups the I2C interface and hardware
47
47
* @param prescale
48
48
* Sets External Clock (Optional)
49
- *
49
+ *
50
50
*/
51
51
void Adafruit_PWMServoDriver::begin (uint8_t prescale) {
52
52
_i2c->begin ();
@@ -158,13 +158,38 @@ void Adafruit_PWMServoDriver::setPWMFreq(float freq) {
158
158
#endif
159
159
}
160
160
161
+ /* !
162
+ * @brief Sets the output mode of the PCA9685 to either
163
+ * open drain or push pull / totempole.
164
+ * Warning: LEDs with integrated zener diodes should
165
+ * only be driven in open drain mode.
166
+ * @param totempole Totempole if true, open drain if false.
167
+ */
168
+ void Adafruit_PWMServoDriver::setOutputMode (bool totempole) {
169
+ uint8_t oldmode = read8 (PCA9685_MODE2);
170
+ uint8_t newmode;
171
+ if (totempole) {
172
+ newmode = (oldmode&0x7F ) | 0x04 ;
173
+ }
174
+ else {
175
+ newmode = (oldmode&0x7F ) & ~0x04 ;
176
+ }
177
+ write8 (PCA9685_MODE2, newmode);
178
+ #ifdef ENABLE_DEBUG_OUTPUT
179
+ Serial.print (" Setting output mode: " );
180
+ Serial.print (totempole ? " totempole" : " open drain" );
181
+ Serial.print (" by setting MODE2 to " );
182
+ Serial.println (newmode);
183
+ #endif
184
+ }
185
+
161
186
/* !
162
187
* @brief Gets the PWM output of one of the PCA9685 pins
163
188
* @param num One of the PWM output pins, from 0 to 15
164
189
* @return requested PWM output value
165
190
*/
166
191
uint8_t Adafruit_PWMServoDriver::getPWM (uint8_t num) {
167
- _i2c->requestFrom ((uint8_t )_i2caddr, LED0_ON_L + 4 * num, (uint8_t )4 );
192
+ _i2c->requestFrom ((int )_i2caddr, LED0_ON_L + 4 * num, (int )4 );
168
193
return _i2c->read ();
169
194
}
170
195
0 commit comments