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.

Committer:
UCSBRobotics
Date:
Wed Aug 01 22:28:33 2012 +0000
Revision:
2:19f995979c6a
Child:
3:5357104c16a6
Copied from PWMTest

Who changed what in which revision?

UserRevisionLine numberNew contents of line
UCSBRobotics 2:19f995979c6a 1 #ifndef SERVO_H
UCSBRobotics 2:19f995979c6a 2 #define SERVO_H
UCSBRobotics 2:19f995979c6a 3
UCSBRobotics 2:19f995979c6a 4 #include "mbed.h"
UCSBRobotics 2:19f995979c6a 5
UCSBRobotics 2:19f995979c6a 6
UCSBRobotics 2:19f995979c6a 7
UCSBRobotics 2:19f995979c6a 8 class Servo
UCSBRobotics 2:19f995979c6a 9 {
UCSBRobotics 2:19f995979c6a 10 public:
UCSBRobotics 2:19f995979c6a 11 Servo(PinName pin, unsigned int width = 1500);
UCSBRobotics 2:19f995979c6a 12 void write(int width);
UCSBRobotics 2:19f995979c6a 13 int read();
UCSBRobotics 2:19f995979c6a 14 void operator=(int width);
UCSBRobotics 2:19f995979c6a 15 operator int();
UCSBRobotics 2:19f995979c6a 16
UCSBRobotics 2:19f995979c6a 17 protected:
UCSBRobotics 2:19f995979c6a 18 static unsigned int numServos;
UCSBRobotics 2:19f995979c6a 19 static Servo *servos[];
UCSBRobotics 2:19f995979c6a 20 static const unsigned int period = 20000;
UCSBRobotics 2:19f995979c6a 21 static Timeout refreshTimeout;
UCSBRobotics 2:19f995979c6a 22 Timeout servoTimeout;
UCSBRobotics 2:19f995979c6a 23 unsigned int pulseWidth;
UCSBRobotics 2:19f995979c6a 24 DigitalOut signalPin;
UCSBRobotics 2:19f995979c6a 25
UCSBRobotics 2:19f995979c6a 26 static void refresh();
UCSBRobotics 2:19f995979c6a 27 void timeout();
UCSBRobotics 2:19f995979c6a 28 };
UCSBRobotics 2:19f995979c6a 29
UCSBRobotics 2:19f995979c6a 30 #endif // SERVO_H