File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,31 @@ 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 pushPull 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
Original file line number Diff line number Diff line change 19
19
*
20
20
* BSD license, all text above must be included in any redistribution
21
21
*/
22
-
23
22
#ifndef _ADAFRUIT_PWMServoDriver_H
24
23
#define _ADAFRUIT_PWMServoDriver_H
25
24
31
30
#define PCA9685_SUBADR3 0x4 /* *< i2c bus address 3 */
32
31
33
32
#define PCA9685_MODE1 0x0 /* *< Mode Register 1 */
33
+ #define PCA9685_MODE2 0x1 /* *< Mode Register 2 */
34
34
#define PCA9685_PRESCALE 0xFE /* *< Prescaler for PWM output frequency */
35
35
36
36
#define LED0_ON_L 0x6 /* *< LED0 output and brightness control byte 0 */
@@ -55,6 +55,7 @@ class Adafruit_PWMServoDriver {
55
55
void wakeup ();
56
56
void setExtClk (uint8_t prescale);
57
57
void setPWMFreq (float freq);
58
+ void setOutputMode (bool totempole);
58
59
uint8_t getPWM (uint8_t num);
59
60
void setPWM (uint8_t num, uint16_t on, uint16_t off);
60
61
void setPin (uint8_t num, uint16_t val, bool invert=false );
You can’t perform that action at this time.
0 commit comments