A simple library for driving RC servos without using the mbed's PWM functions. This allows the mbed to drive as many servos as there are DigitalOut pins, and additionally allows for the PWM functions to be used at a different frequency than the 50Hz used for servos.

Revision:
9:6bfea9af4dcb
Parent:
7:ff85ac12e11b
Child:
11:79862bf306c1
Child:
13:896410a1b594
--- a/Servo.h	Wed Oct 03 07:28:03 2012 +0000
+++ b/Servo.h	Sun Oct 21 00:03:06 2012 +0000
@@ -8,10 +8,14 @@
 class Servo
 {
 public:
-    Servo(PinName pin, unsigned int width = 1500);
-    void write(int width);
-    int read();
-    void operator=(int width);
+    Servo(PinName pin);
+    bool calibrate(unsigned int plus60, unsigned int minus60, float upperLimit, float lowerLimit);
+    void write(float degrees);
+    void writeWidth(unsigned int width);
+    float read();
+    int readWidth();
+    void operator=(float degrees);
+    operator float();
     operator int();
     
 protected:
@@ -23,6 +27,11 @@
     unsigned int pulseWidth;
     DigitalOut signalPin;
     
+    unsigned int center;
+    float usPerDegree;
+    float upperLimit;
+    float lowerLimit;
+    
     static void refresh();
     void timeout();
 };