Skip to content

Commit 64077df

Browse files
authored
Keep Servo in the same position after re-attaching (#8753)
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.
1 parent 9cd560b commit 64077df

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

libraries/Servo/src/Servo.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Servo::~Servo() {
5858

5959
uint8_t Servo::attach(int pin)
6060
{
61-
return attach(pin, DEFAULT_MIN_PULSE_WIDTH, DEFAULT_MAX_PULSE_WIDTH);
61+
return attach(pin, _minUs, _maxUs);
6262
}
6363

6464
uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
@@ -94,7 +94,6 @@ void Servo::detach()
9494
delay(REFRESH_INTERVAL / 1000); // long enough to complete active period under all circumstances.
9595
stopWaveform(_pin);
9696
_attached = false;
97-
_valueUs = DEFAULT_NEUTRAL_PULSE_WIDTH;
9897
}
9998
}
10099

libraries/Servo/src/Servo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
//
3030
// attach(pin) - Attaches a servo motor to an i/o pin.
3131
// attach(pin, min, max) - Attaches to a pin setting min and max values in microseconds
32-
// default min is 1000, max is 2000
32+
// attach(pin, min, max, value) - Attaches to a pin setting min, max, and current values in microseconds
33+
// default min is 1000, max is 2000, and value is 1500.
3334
//
3435
// write() - Sets the servo angle in degrees. (invalid angle that is valid as pulse in microseconds is treated as microseconds)
3536
// writeMicroseconds() - Sets the servo pulse width in microseconds

0 commit comments

Comments
 (0)