A class to control a model R/C servo, using a PwmOut. Modified to account for PWM inversion that occurs with level-shifting on custom PCB.

Fork of Servo by Simon Ford

Revision:
4:9a48389dcf50
Parent:
2:8995c167f399
--- a/Servo.cpp	Thu Sep 02 17:34:43 2010 +0000
+++ b/Servo.cpp	Sun May 20 02:54:53 2018 +0000
@@ -41,13 +41,13 @@
 
 void Servo::write(float percent) {
     float offset = _range * 2.0 * (percent - 0.5);
-    _pwm.pulsewidth(0.0015 + clamp(offset, -_range, _range));
+    _pwm.pulsewidth(0.02 - (0.0015 + clamp(offset, -_range, _range)));
     _p = clamp(percent, 0.0, 1.0);
 }
 
 void Servo::position(float degrees) {
     float offset = _range * (degrees / _degrees);
-    _pwm.pulsewidth(0.0015 + clamp(offset, -_range, _range));
+    _pwm.pulsewidth(0.02 - (0.0015 + clamp(offset, -_range, _range)));
 }
 
 void Servo::calibrate(float range, float degrees) {