@@ -28,7 +28,6 @@ SOFTWARE.
28
28
// Constructor
29
29
Servo::Servo ()
30
30
{
31
-
32
31
}
33
32
34
33
void Servo::attach (uint8_t pinNumber, uint16_t minMicros, uint16_t maxMicros)
@@ -51,15 +50,22 @@ void Servo::write(uint8_t servoPosition)
51
50
_servoPosition = 180 ; // Bounds check
52
51
53
52
uint16_t newServoPosition = map (servoPosition, 0 , 181 , 0 , ((uint16_t )0x01 << getServoResolution ()));
54
-
55
53
servoWrite (_servoPinNumber, newServoPosition, _minMicros, _maxMicros);
56
54
}
57
55
58
56
void Servo::writeMicroseconds (uint16_t microSecs)
59
57
{
60
- // Convert microseconds to PWM value
61
- uint16_t newServoPosition = microSecs;
62
- servoWrite (_servoPinNumber, newServoPosition, _minMicros, _maxMicros);
58
+ uint16_t extendedMin = _minMicros;
59
+ uint16_t extendedMax = _maxMicros;
60
+
61
+ if (microSecs > _maxMicros)
62
+ extendedMax = microSecs;
63
+ if (microSecs < _minMicros)
64
+ extendedMin = microSecs;
65
+
66
+ // Map microseconds to PWM value
67
+ uint16_t newServoPosition = map (microSecs, extendedMin, extendedMax + 1 , 0 , ((uint16_t )0x01 << getServoResolution ()));
68
+ servoWrite (_servoPinNumber, newServoPosition, extendedMin, extendedMax);
63
69
}
64
70
65
71
void Servo::detach (void )
0 commit comments