Skip to content

Commit c551dc2

Browse files
committed
Stricter checks for configured, and default, bounded timings.
1 parent 4c4906f commit c551dc2

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

libraries/Servo/src/Servo.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,13 @@ void Servo::write(int value)
105105
// assumed to be 0-180 degrees servo
106106
value = constrain(value, 0, 180);
107107
value = improved_map(value, 0, 180, _minUs, _maxUs);
108-
} else if (value > _maxUs) {
109-
value = _maxUs;
110108
}
111109
writeMicroseconds(value);
112110
}
113111

114112
void Servo::writeMicroseconds(int value)
115113
{
114+
value = constrain(value, _minUs, _maxUs);
116115
_valueUs = value;
117116
if (_attached) {
118117
_servoMap &= ~(1 << _pin);

libraries/Servo/src/Servo.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646

4747
// the following are in us (microseconds)
4848
//
49-
#define DEFAULT_MIN_PULSE_WIDTH 800 // the shortest duty cycle sent to a servo
50-
#define DEFAULT_MAX_PULSE_WIDTH 2190 // the longest duty cycle sent to a servo
49+
#define DEFAULT_MIN_PULSE_WIDTH 1000 // uncalibrated default, the shortest duty cycle sent to a servo
50+
#define DEFAULT_MAX_PULSE_WIDTH 2000 // uncalibrated default, the longest duty cycle sent to a servo
5151
#define DEFAULT_NEUTRAL_PULSE_WIDTH 1500 // default duty cycle when servo is attached
5252
#define REFRESH_INTERVAL 20000 // classic default period to refresh servos in microseconds
5353
#define MAX_SERVOS 9 // D0-D8

0 commit comments

Comments
 (0)