1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-18 23:03:34 +03:00

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.
This commit is contained in:
Dirk O. Kaar
2022-12-15 00:21:56 +01:00
committed by GitHub
parent 9cd560b451
commit 64077df980
2 changed files with 3 additions and 3 deletions

View File

@ -58,7 +58,7 @@ Servo::~Servo() {
uint8_t Servo::attach(int pin) 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) uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
@ -94,7 +94,6 @@ void Servo::detach()
delay(REFRESH_INTERVAL / 1000); // long enough to complete active period under all circumstances. delay(REFRESH_INTERVAL / 1000); // long enough to complete active period under all circumstances.
stopWaveform(_pin); stopWaveform(_pin);
_attached = false; _attached = false;
_valueUs = DEFAULT_NEUTRAL_PULSE_WIDTH;
} }
} }

View File

@ -29,7 +29,8 @@
// //
// attach(pin) - Attaches a servo motor to an i/o pin. // 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 // 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) // 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 // writeMicroseconds() - Sets the servo pulse width in microseconds