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:
Thu Aug 30 03:36:03 2012 +0000
Revision:
7:ff85ac12e11b
Parent:
3:5357104c16a6
Child:
9:6bfea9af4dcb
Fixed to allow for servos to be created with global scope.

Who changed what in which revision?

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