Skip to content

Commit

Permalink
Add ability to detect I2C errors within setPWM() while compatible wit…
Browse files Browse the repository at this point in the history
…h existing code
  • Loading branch information
waynepiekarski committed Jun 22, 2022
1 parent d265f74 commit 15f7f91
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Adafruit_PWMServoDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,10 @@ uint8_t Adafruit_PWMServoDriver::getPWM(uint8_t num) {
* @param num One of the PWM output pins, from 0 to 15
* @param on At what point in the 4096-part cycle to turn the PWM output ON
* @param off At what point in the 4096-part cycle to turn the PWM output OFF
* @return result from endTransmission
*/
void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
uint8_t Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on,
uint16_t off) {
#ifdef ENABLE_DEBUG_OUTPUT
Serial.print("Setting PWM ");
Serial.print(num);
Expand All @@ -235,7 +237,7 @@ void Adafruit_PWMServoDriver::setPWM(uint8_t num, uint16_t on, uint16_t off) {
_i2c->write(on >> 8);
_i2c->write(off);
_i2c->write(off >> 8);
_i2c->endTransmission();
return _i2c->endTransmission();
}

/*!
Expand Down
2 changes: 1 addition & 1 deletion Adafruit_PWMServoDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Adafruit_PWMServoDriver {
void setPWMFreq(float freq);
void setOutputMode(bool totempole);
uint8_t getPWM(uint8_t num);
void setPWM(uint8_t num, uint16_t on, uint16_t off);
uint8_t setPWM(uint8_t num, uint16_t on, uint16_t off);
void setPin(uint8_t num, uint16_t val, bool invert = false);
uint8_t readPrescale(void);
void writeMicroseconds(uint8_t num, uint16_t Microseconds);
Expand Down

0 comments on commit 15f7f91

Please sign in to comment.