diff --git a/library/stm32f072xb/motor/servo/servo.hpp b/library/stm32f072xb/motor/servo/servo.hpp index 9e9b55cbac7e9e64216a687860a328f162bf3843..9ef16648cd6d48b28f76aaac6ac2725aad4c5b6f 100644 --- a/library/stm32f072xb/motor/servo/servo.hpp +++ b/library/stm32f072xb/motor/servo/servo.hpp @@ -82,21 +82,16 @@ class Servo { if (angle < _minAngle) { angle = _minAngle; } + if (_currentAngle == angle) { + return; + } _currentAngle = angle; uint16_t dutyCycle = _zeroDegreeDutyCycle + _scaler * angle; _timer.setDutyCycle(dutyCycle); } - void incrementAngle() { - if (_currentAngle < _maxAngle) { - setAngle(++_currentAngle); - } - } - void decrementAngle() { - if (_currentAngle > _minAngle) { - setAngle(--_currentAngle); - } - } + void incrementAngle(uint16_t amount = 1) { setAngle(_currentAngle + amount); } + void decrementAngle(int16_t amount = 1) { setAngle(_currentAngle - amount); } }; #endif