@@ -46,9 +46,9 @@ int improved_map(int value, int minIn, int maxIn, int minOut, int maxOut)
46
46
Servo::Servo ()
47
47
{
48
48
_attached = false ;
49
- _valueUs = DEFAULT_PULSE_WIDTH ;
50
- _minUs = MIN_PULSE_WIDTH ;
51
- _maxUs = MAX_PULSE_WIDTH ;
49
+ _valueUs = DEFAULT_NEUTRAL_PULSE_WIDTH ;
50
+ _minUs = DEFAULT_MIN_PULSE_WIDTH ;
51
+ _maxUs = DEFAULT_MAX_PULSE_WIDTH ;
52
52
}
53
53
54
54
Servo::~Servo () {
@@ -58,7 +58,7 @@ Servo::~Servo() {
58
58
59
59
uint8_t Servo::attach (int pin)
60
60
{
61
- return attach (pin, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH );
61
+ return attach (pin, DEFAULT_MIN_PULSE_WIDTH, DEFAULT_MAX_PULSE_WIDTH );
62
62
}
63
63
64
64
uint8_t Servo::attach (int pin, uint16_t minUs, uint16_t maxUs)
@@ -70,11 +70,11 @@ uint8_t Servo::attach(int pin, uint16_t minUs, uint16_t maxUs)
70
70
_attached = true ;
71
71
}
72
72
73
- // keep the min and max within 200-3000 us, these are extreme
73
+ // keep the min and max within 500-2500 us, these are extreme
74
74
// ranges and should support extreme servos while maintaining
75
75
// reasonable ranges
76
- _maxUs = max ((uint16_t )250 , min ((uint16_t )3000 , maxUs));
77
- _minUs = max ((uint16_t )200 , min (_maxUs, minUs));
76
+ _maxUs = max ((uint16_t )550 , min ((uint16_t )2500 , maxUs));
77
+ _minUs = max ((uint16_t )500 , min (_maxUs, minUs));
78
78
79
79
write (_valueUs);
80
80
@@ -97,9 +97,11 @@ void Servo::write(int value)
97
97
if (value < _minUs) {
98
98
// assumed to be 0-180 degrees servo
99
99
value = constrain (value, 0 , 180 );
100
- // writeMicroseconds will contrain the calculated value for us
100
+ // writeMicroseconds will contain the calculated value for us
101
101
// for any user defined min and max, but we must use default min max
102
102
value = improved_map (value, 0 , 180 , _minUs, _maxUs);
103
+ } else if (value > _maxUs) {
104
+ value = constrain (value, _minUs, _maxUs);
103
105
}
104
106
writeMicroseconds (value);
105
107
}
0 commit comments