Skip to content

Commit 4dbf2f0

Browse files
committed
Merge branch 'master' of github.com:hoffmannjan/Adafruit-PWM-Servo-Driver-Library
2 parents bae5a0e + d6ef5ec commit 4dbf2f0

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

Adafruit_PWMServoDriver.cpp

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
/*!
3434
* @brief Instantiates a new PCA9685 PWM driver chip with the I2C address on a
3535
* TwoWire interface
36+
* @param addr The 7-bit I2C address to locate this chip, default is 0x40
3637
* @param i2c A pointer to a 'Wire' compatible object that we'll use to
3738
* communicate with
38-
* @param addr The 7-bit I2C address to locate this chip, default is 0x40
3939
*/
40-
Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(TwoWire *i2c, uint8_t addr) {
40+
Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(uint8_t addr, TwoWire *i2c) {
4141
_i2c = i2c;
4242
_i2caddr = addr;
4343
}
@@ -46,7 +46,7 @@ Adafruit_PWMServoDriver::Adafruit_PWMServoDriver(TwoWire *i2c, uint8_t addr) {
4646
* @brief Setups the I2C interface and hardware
4747
* @param prescale
4848
* Sets External Clock (Optional)
49-
*
49+
*
5050
*/
5151
void Adafruit_PWMServoDriver::begin(uint8_t prescale) {
5252
_i2c->begin();
@@ -158,13 +158,38 @@ void Adafruit_PWMServoDriver::setPWMFreq(float freq) {
158158
#endif
159159
}
160160

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+
161186
/*!
162187
* @brief Gets the PWM output of one of the PCA9685 pins
163188
* @param num One of the PWM output pins, from 0 to 15
164189
* @return requested PWM output value
165190
*/
166191
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);
168193
return _i2c->read();
169194
}
170195

Adafruit_PWMServoDriver.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
*
2020
* BSD license, all text above must be included in any redistribution
2121
*/
22-
2322
#ifndef _ADAFRUIT_PWMServoDriver_H
2423
#define _ADAFRUIT_PWMServoDriver_H
2524

@@ -31,6 +30,7 @@
3130
#define PCA9685_SUBADR3 0x4 /**< i2c bus address 3 */
3231

3332
#define PCA9685_MODE1 0x0 /**< Mode Register 1 */
33+
#define PCA9685_MODE2 0x1 /**< Mode Register 2 */
3434
#define PCA9685_PRESCALE 0xFE /**< Prescaler for PWM output frequency */
3535

3636
#define LED0_ON_L 0x6 /**< LED0 output and brightness control byte 0 */
@@ -48,13 +48,14 @@
4848
*/
4949
class Adafruit_PWMServoDriver {
5050
public:
51-
Adafruit_PWMServoDriver(TwoWire *I2C = &Wire, uint8_t addr = 0x40);
51+
Adafruit_PWMServoDriver(uint8_t addr = 0x40, TwoWire *I2C = &Wire);
5252
void begin(uint8_t prescale = 0);
5353
void reset();
5454
void sleep();
5555
void wakeup();
5656
void setExtClk(uint8_t prescale);
5757
void setPWMFreq(float freq);
58+
void setOutputMode(bool totempole);
5859
uint8_t getPWM(uint8_t num);
5960
void setPWM(uint8_t num, uint16_t on, uint16_t off);
6061
void setPin(uint8_t num, uint16_t val, bool invert=false);

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Adafruit PCA9685 PWM Servo Driver Library [![Build Status](https://travis-ci.org/adafruit/Adafruit_PWMServoDriver.svg?branch=master)](https://travis-ci.org/adafruit/Adafruit_PWMServoDriver)
1+
# Adafruit PCA9685 PWM Servo Driver Library [![Build Status](https://travis-ci.com/adafruit/Adafruit-PWM-Servo-Driver-Library.svg?branch=master)](https://travis-ci.com/adafruit/Adafruit-PWM-Servo-Driver-Library)
22

33
This is a library for our Adafruit 16-channel PWM & Servo driver, shield or FeatherWing
44

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit PWM Servo Driver Library
2-
version=1.0.2
2+
version=1.0.4
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Adafruit PWM Servo Driver Library

0 commit comments

Comments
 (0)