From 64077df9804060cd09c56025608913db48f8d352 Mon Sep 17 00:00:00 2001 From: "Dirk O. Kaar" <19971886+dok-net@users.noreply.github.com> Date: Thu, 15 Dec 2022 00:21:56 +0100 Subject: [PATCH] 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. --- libraries/Servo/src/Servo.cpp | 3 +-- libraries/Servo/src/Servo.h | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Servo/src/Servo.cpp b/libraries/Servo/src/Servo.cpp index 69ed476d84..1d19f62683 100644 --- a/libraries/Servo/src/Servo.cpp +++ b/libraries/Servo/src/Servo.cpp @@ -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) @@ -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; } } diff --git a/libraries/Servo/src/Servo.h b/libraries/Servo/src/Servo.h index 9efb7b2c0d..d40939c2aa 100644 --- a/libraries/Servo/src/Servo.h +++ b/libraries/Servo/src/Servo.h @@ -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