Skip to content

Commit 269d168

Browse files
committed
fix Servo detach issue
1 parent c84672a commit 269d168

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

libraries/Servo/src/nrf52/Servo.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ uint8_t Servo::attach(int pin, int min, int max)
4747
pinMode(pin, OUTPUT); // set servo pin to output
4848
servos[this->servoIndex].Pin.nbr = pin;
4949

50-
if(min < MIN_PULSE_WIDTH) min = MIN_PULSE_WIDTH;
50+
if (min < MIN_PULSE_WIDTH) min = MIN_PULSE_WIDTH;
5151
if (max > MAX_PULSE_WIDTH) max = MAX_PULSE_WIDTH;
5252

5353
//fix min if conversion to pulse cycle value is too low
@@ -77,8 +77,12 @@ uint8_t Servo::attach(int pin, int min, int max)
7777

7878
void Servo::detach()
7979
{
80+
uint8_t const pin = servos[this->servoIndex].Pin.nbr;
81+
8082
servos[this->servoIndex].Pin.isActive = false;
81-
// TODO Adafruit remove pin from HW PWM
83+
84+
// remove pin from HW PWM
85+
this->pwm->removePin(pin);
8286
}
8387

8488

@@ -108,7 +112,7 @@ int Servo::read() // return the value as degrees
108112

109113
int Servo::readMicroseconds()
110114
{
111-
uint8_t pin=servos[this->servoIndex].Pin.nbr;
115+
uint8_t pin = servos[this->servoIndex].Pin.nbr;
112116

113117
if ( this->pwm ) return this->pwm->readPin(pin)*DUTY_CYCLE_RESOLUTION;
114118

0 commit comments

Comments
 (0)