Skip to content

Commit cce5267

Browse files
dok-nethasenradball
authored andcommitted
Keep Servo in the same position after re-attaching (esp8266#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 686c053 commit cce5267

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

libraries/Servo/src/Servo.cpp

+1-2
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

+2-1
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)