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.

Servo.h

Committer:
pclary
Date:
2013-01-09
Revision:
14:0eff26aa0d17
Parent:
13:896410a1b594
Parent:
11:79862bf306c1
Child:
15:55221f9de707

File content as of revision 14:0eff26aa0d17:

#ifndef SERVO_H
#define SERVO_H

#include "mbed.h"



class Servo
{
public:
    Servo(PinName pin);
    bool calibrate(unsigned int plus45, unsigned int minus45, 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();
    
    unsigned int center;
    float usPerDegree;
    float upperLimit;
    float lowerLimit;
    
protected:
    static unsigned int numServos;
    static Servo *servos[];
    static const unsigned int period = 20000;
    static Ticker* refreshTicker;
    Timeout servoTimeout;
    unsigned int pulseWidth;
    DigitalOut signalPin;
    
    
    
    static void refresh();
    void timeout();
};

#endif // SERVO_H