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:
2012-10-21
Revision:
11:79862bf306c1
Parent:
9:6bfea9af4dcb
Child:
14:0eff26aa0d17

File content as of revision 11:79862bf306c1:

#ifndef SERVO_H
#define SERVO_H

#include "mbed.h"



class Servo
{
public:
    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();
    
    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