Skip to content

Commit

Permalink
Keep Servo in the same position after re-attaching (#8753)
Browse files Browse the repository at this point in the history
The current implementation of the Servo lib always resets the position when detaching.
In AVR Servo, this isn't the case, instead, it doesn't move the servo but leaves it as it was before getting detached.
  • Loading branch information
dok-net authored Dec 14, 2022
1 parent 9cd560b commit 64077df
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
3 changes: 1 addition & 2 deletions libraries/Servo/src/Servo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Servo::~Servo() {

uint8_t Servo::attach(int pin)
{
return attach(pin, DEFAULT_MIN_PULSE_WIDTH, DEFAULT_MAX_PULSE_WIDTH);
return attach(pin, _minUs, _maxUs);
}

uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
Expand Down Expand Up @@ -94,7 +94,6 @@ void Servo::detach()
delay(REFRESH_INTERVAL / 1000); // long enough to complete active period under all circumstances.
stopWaveform(_pin);
_attached = false;
_valueUs = DEFAULT_NEUTRAL_PULSE_WIDTH;
}
}

Expand Down
3 changes: 2 additions & 1 deletion libraries/Servo/src/Servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
//
// attach(pin) - Attaches a servo motor to an i/o pin.
// attach(pin, min, max) - Attaches to a pin setting min and max values in microseconds
// default min is 1000, max is 2000
// attach(pin, min, max, value) - Attaches to a pin setting min, max, and current values in microseconds
// default min is 1000, max is 2000, and value is 1500.
//
// write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds)
// writeMicroseconds() - Sets the servo pulse width in microseconds
Expand Down

0 comments on commit 64077df

Please sign in to comment.