Skip to content

Commit 15f7f91

Browse files
Add ability to detect I2C errors within setPWM() while compatible with existing code
1 parent d265f74 commit 15f7f91

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Adafruit_PWMServoDriver.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,10 @@ uint8_t Adafruit_PWMServoDriver::getPWM(uint8_t num) {
218218
* @param num One of the PWM output pins, from 0 to 15
219219
* @param on At what point in the 4096-part cycle to turn the PWM output ON
220220
* @param off At what point in the 4096-part cycle to turn the PWM output OFF
221+
* @return result from endTransmission
221222
*/
222-
void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
223+
uint8_t Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on,
224+
uint16_t off) {
223225
#ifdef ENABLE_DEBUG_OUTPUT
224226
Serial.print("Setting PWM ");
225227
Serial.print(num);
@@ -235,7 +237,7 @@ void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
235237
_i2c->write(on >> 8);
236238
_i2c->write(off);
237239
_i2c->write(off >> 8);
238-
_i2c->endTransmission();
240+
return _i2c->endTransmission();
239241
}
240242

241243
/*!

Adafruit_PWMServoDriver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Adafruit_PWMServoDriver {
8585
void setPWMFreq(float freq);
8686
void setOutputMode(bool totempole);
8787
uint8_t getPWM(uint8_t num);
88-
void setPWM(uint8_t num, uint16_t on, uint16_t off);
88+
uint8_t setPWM(uint8_t num, uint16_t on, uint16_t off);
8989
void setPin(uint8_t num, uint16_t val, bool invert = false);
9090
uint8_t readPrescale(void);
9191
void writeMicroseconds(uint8_t num, uint16_t Microseconds);

0 commit comments

Comments
 (0)