Dependencies:   mbed

Committer:
alex89
Date:
Sun Dec 06 07:29:17 2009 +0000
Revision:
0:76b1b51d98f6

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alex89 0:76b1b51d98f6 1 /* mbed Microcontroller Library - Servo
alex89 0:76b1b51d98f6 2 * Copyright (c) 2007-2008, sford
alex89 0:76b1b51d98f6 3 */
alex89 0:76b1b51d98f6 4
alex89 0:76b1b51d98f6 5 #ifndef MBED_SERVO_H
alex89 0:76b1b51d98f6 6 #define MBED_SERVO_H
alex89 0:76b1b51d98f6 7
alex89 0:76b1b51d98f6 8 #include "Servo.h"
alex89 0:76b1b51d98f6 9
alex89 0:76b1b51d98f6 10 #include "mbed.h"
alex89 0:76b1b51d98f6 11 #include "platform.h"
alex89 0:76b1b51d98f6 12
alex89 0:76b1b51d98f6 13
alex89 0:76b1b51d98f6 14 namespace mbed {
alex89 0:76b1b51d98f6 15
alex89 0:76b1b51d98f6 16 /* Class: Servo
alex89 0:76b1b51d98f6 17 * Abstraction on top of PwmOut to control the position of a servo motor
alex89 0:76b1b51d98f6 18 *
alex89 0:76b1b51d98f6 19 * Example:
alex89 0:76b1b51d98f6 20 * > // Continuously sweep the servo through it's full range
alex89 0:76b1b51d98f6 21 * >
alex89 0:76b1b51d98f6 22 * > #include "mbed.h"
alex89 0:76b1b51d98f6 23 * > #include "Servo.h"
alex89 0:76b1b51d98f6 24 * >
alex89 0:76b1b51d98f6 25 * > Servo myServo (p21);
alex89 0:76b1b51d98f6 26 * > int main() {
alex89 0:76b1b51d98f6 27 * > int i;
alex89 0:76b1b51d98f6 28 * > while (1) {
alex89 0:76b1b51d98f6 29 * > for (i=0 ; i<100 ; i++){
alex89 0:76b1b51d98f6 30 * > myServo = i/100.0;
alex89 0:76b1b51d98f6 31 * > wait (0.01);
alex89 0:76b1b51d98f6 32 * > }
alex89 0:76b1b51d98f6 33 * > for (i=100 ; i>0 ; i--){
alex89 0:76b1b51d98f6 34 * > myServo = i/100.0;
alex89 0:76b1b51d98f6 35 * > wait (0.01);
alex89 0:76b1b51d98f6 36 * > }
alex89 0:76b1b51d98f6 37 * > }
alex89 0:76b1b51d98f6 38 * >}
alex89 0:76b1b51d98f6 39 */
alex89 0:76b1b51d98f6 40
alex89 0:76b1b51d98f6 41
alex89 0:76b1b51d98f6 42 class Servo : public Base {
alex89 0:76b1b51d98f6 43
alex89 0:76b1b51d98f6 44 public:
alex89 0:76b1b51d98f6 45 /* Constructor: Servo
alex89 0:76b1b51d98f6 46 * Create a servo object connected to the specified PwmOut pin
alex89 0:76b1b51d98f6 47 *
alex89 0:76b1b51d98f6 48 * Variables:
alex89 0:76b1b51d98f6 49 * pin - PwmOut pin to connect to
alex89 0:76b1b51d98f6 50 */
alex89 0:76b1b51d98f6 51 Servo(PinName pin, const char* = NULL);
alex89 0:76b1b51d98f6 52
alex89 0:76b1b51d98f6 53 /* Function: write
alex89 0:76b1b51d98f6 54 * Set the servo position, normalised to it's full range
alex89 0:76b1b51d98f6 55 *
alex89 0:76b1b51d98f6 56 * Variables:
alex89 0:76b1b51d98f6 57 * percent - A normalised number 0.0-1.0 to represent the full range.
alex89 0:76b1b51d98f6 58 */
alex89 0:76b1b51d98f6 59 void write(float percent);
alex89 0:76b1b51d98f6 60 /* Function: read
alex89 0:76b1b51d98f6 61 * Read the servo motors current position
alex89 0:76b1b51d98f6 62 *
alex89 0:76b1b51d98f6 63 * Variables:
alex89 0:76b1b51d98f6 64 * returns - A normalised number 0.0-1.0 representing the full range.
alex89 0:76b1b51d98f6 65 */
alex89 0:76b1b51d98f6 66 float read();
alex89 0:76b1b51d98f6 67 /* Function: operator=
alex89 0:76b1b51d98f6 68 * Shorthand for the write and read functions
alex89 0:76b1b51d98f6 69 */
alex89 0:76b1b51d98f6 70 Servo& operator= (float percent);
alex89 0:76b1b51d98f6 71 Servo& operator= (Servo& rhs);
alex89 0:76b1b51d98f6 72 operator float();
alex89 0:76b1b51d98f6 73
alex89 0:76b1b51d98f6 74 #ifdef MBED_RPC
alex89 0:76b1b51d98f6 75 virtual const struct rpc_method *get_rpc_methods();
alex89 0:76b1b51d98f6 76 static struct rpc_class *get_rpc_class();
alex89 0:76b1b51d98f6 77 #endif
alex89 0:76b1b51d98f6 78
alex89 0:76b1b51d98f6 79 protected:
alex89 0:76b1b51d98f6 80
alex89 0:76b1b51d98f6 81 PwmOut _pwm;
alex89 0:76b1b51d98f6 82 float _p;
alex89 0:76b1b51d98f6 83 };
alex89 0:76b1b51d98f6 84
alex89 0:76b1b51d98f6 85 }
alex89 0:76b1b51d98f6 86
alex89 0:76b1b51d98f6 87 #endif