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:
UCSBRobotics
Date:
2012-08-01
Revision:
2:19f995979c6a
Child:
3:5357104c16a6

File content as of revision 2:19f995979c6a:

#ifndef SERVO_H
#define SERVO_H

#include "mbed.h"



class Servo
{
public:
    Servo(PinName pin, unsigned int width = 1500);
    void write(int width);
    int read();
    void operator=(int width);
    operator int();
    
protected:
    static unsigned int numServos;
    static Servo *servos[];
    static const unsigned int period = 20000;
    static Timeout refreshTimeout;
    Timeout servoTimeout;
    unsigned int pulseWidth;
    DigitalOut signalPin;
    
    static void refresh();
    void timeout();
};

#endif // SERVO_H