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@3:5357104c16a6, 2012-08-02 (annotated)
- Committer:
- UCSBRobotics
- Date:
- Thu Aug 02 02:29:10 2012 +0000
- Revision:
- 3:5357104c16a6
- Parent:
- 2:19f995979c6a
- Child:
- 7:ff85ac12e11b
Updated with Servo lib in PWMTest: changed refresh timeout to ticker
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:5357104c16a6 | 21 | static Ticker refreshTicker; |
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 |