Skip to content

Commit 18f643c

Browse files
tagno25earlephilhower
authored andcommitted
Fix min and max for Servo library (#5064)
Use the optionally defined min/max values instead of the hard-coded limits for pulse widths.
1 parent 85e6809 commit 18f643c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libraries/Servo/src/Servo.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ void Servo::detach()
9191
void Servo::write(int value)
9292
{
9393
// treat values less than 544 as angles in degrees (valid values in microseconds are handled as microseconds)
94-
if (value < MIN_PULSE_WIDTH) {
94+
if (value < _minUs) {
9595
// assumed to be 0-180 degrees servo
9696
value = constrain(value, 0, 180);
9797
// writeMicroseconds will contrain the calculated value for us
9898
// for any user defined min and max, but we must use default min max
99-
value = improved_map(value, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
99+
value = improved_map(value, 0, 180, _minUs, _maxUs);
100100
}
101101
writeMicroseconds(value);
102102
}
@@ -113,7 +113,7 @@ int Servo::read() // return the value as degrees
113113
{
114114
// read returns the angle for an assumed 0-180, so we calculate using
115115
// the normal min/max constants and not user defined ones
116-
return improved_map(readMicroseconds(), MIN_PULSE_WIDTH, MAX_PULSE_WIDTH, 0, 180);
116+
return improved_map(readMicroseconds(), _minUs, _maxUs, 0, 180);
117117
}
118118

119119
int Servo::readMicroseconds()

0 commit comments

Comments
 (0)