From 18f643c7e2d6a0da9d26ff2b14c94e6536ab78c1 Mon Sep 17 00:00:00 2001 From: Philip Dorr Date: Mon, 20 Aug 2018 11:01:07 -0500 Subject: [PATCH] Fix min and max for Servo library (#5064) Use the optionally defined min/max values instead of the hard-coded limits for pulse widths. --- libraries/Servo/src/Servo.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/Servo/src/Servo.cpp b/libraries/Servo/src/Servo.cpp index 305d2c82a..57294102b 100644 --- a/libraries/Servo/src/Servo.cpp +++ b/libraries/Servo/src/Servo.cpp @@ -91,12 +91,12 @@ void Servo::detach() void Servo::write(int value) { // treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds) - if (value < MIN_PULSE_WIDTH) { + if (value < _minUs) { // assumed to be 0-180 degrees servo value = constrain(value, 0, 180); // writeMicroseconds will contrain the calculated value for us // for any user defined min and max, but we must use default min max - value = improved_map(value, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); + value = improved_map(value, 0, 180, _minUs, _maxUs); } writeMicroseconds(value); } @@ -113,7 +113,7 @@ int Servo::read() // return the value as degrees { // read returns the angle for an assumed 0-180, so we calculate using // the normal min/max constants and not user defined ones - return improved_map(readMicroseconds(), MIN_PULSE_WIDTH, MAX_PULSE_WIDTH, 0, 180); + return improved_map(readMicroseconds(), _minUs, _maxUs, 0, 180); } int Servo::readMicroseconds()