Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Servo.h
00001 /* mbed Microcontroller Library - Servo 00002 * Copyright (c) 2007-2008, sford 00003 */ 00004 00005 #ifndef MBED_SERVO_H 00006 #define MBED_SERVO_H 00007 00008 #include "Servo.h" 00009 00010 #include "mbed.h" 00011 #include "platform.h" 00012 00013 00014 namespace mbed { 00015 00016 /* Class: Servo 00017 * Abstraction on top of PwmOut to control the position of a servo motor 00018 * 00019 * Example: 00020 * > // Continuously sweep the servo through it's full range 00021 * > 00022 * > #include "mbed.h" 00023 * > #include "Servo.h" 00024 * > 00025 * > Servo myServo (p21); 00026 * > int main() { 00027 * > int i; 00028 * > while (1) { 00029 * > for (i=0 ; i<100 ; i++){ 00030 * > myServo = i/100.0; 00031 * > wait (0.01); 00032 * > } 00033 * > for (i=100 ; i>0 ; i--){ 00034 * > myServo = i/100.0; 00035 * > wait (0.01); 00036 * > } 00037 * > } 00038 * >} 00039 */ 00040 00041 00042 class Servo : public Base { 00043 00044 public: 00045 /* Constructor: Servo 00046 * Create a servo object connected to the specified PwmOut pin 00047 * 00048 * Variables: 00049 * pin - PwmOut pin to connect to 00050 */ 00051 Servo(PinName pin, const char* = NULL); 00052 00053 /* Function: write 00054 * Set the servo position, normalised to it's full range 00055 * 00056 * Variables: 00057 * percent - A normalised number 0.0-1.0 to represent the full range. 00058 */ 00059 void write(float percent); 00060 /* Function: read 00061 * Read the servo motors current position 00062 * 00063 * Variables: 00064 * returns - A normalised number 0.0-1.0 representing the full range. 00065 */ 00066 float read(); 00067 /* Function: operator= 00068 * Shorthand for the write and read functions 00069 */ 00070 Servo& operator= (float percent); 00071 Servo& operator= (Servo& rhs); 00072 operator float(); 00073 00074 #ifdef MBED_RPC 00075 virtual const struct rpc_method *get_rpc_methods(); 00076 static struct rpc_class *get_rpc_class(); 00077 #endif 00078 00079 protected: 00080 00081 PwmOut _pwm; 00082 float _p; 00083 }; 00084 00085 } 00086 00087 #endif
Generated on Thu Jul 14 2022 14:36:03 by
1.7.2