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.
Dependents: followCar script_voor_project
Fork of Servo by
Servo.cpp
00001 /* mbed R/C Servo Library 00002 * 00003 * Copyright (c) 2007-2010 sford, cstyles 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy 00006 * of this software and associated documentation files (the "Software"), to deal 00007 * in the Software without restriction, including without limitation the rights 00008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00009 * copies of the Software, and to permit persons to whom the Software is 00010 * furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included in 00013 * all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00021 * THE SOFTWARE. 00022 */ 00023 00024 #include "Servo.h" 00025 #include "mbed.h" 00026 00027 00028 Servo::Servo(PinName pin) : _pwm(pin) { 00029 00030 _pwm.period_ms(20); 00031 wait(0.5); 00032 } 00033 00034 00035 00036 /* 00037 00038 00039 00040 while(1){ 00041 00042 p.pulsewidth(0.0010); 00043 wait(1); 00044 00045 p.pulsewidth((0.0016+0.0009)/2); 00046 wait(1); 00047 00048 p.pulsewidth(0.0015); 00049 wait(1); 00050 00051 00052 00053 00054 } 00055 00056 */ 00057 00058 00059 00060 00061 00062 00063 void Servo::angle(float ang){ 00064 00065 // l45->0.0010 1000us 00066 // r45->0.0015 1500us 00067 00068 00069 //0.0010 0.0015 00070 // -45 0 45 00071 00072 // m= 250/45 =5.556 00073 00074 //ang*x= 00075 00076 _pwm.pulsewidth_us(ang*5.556+1250); 00077 00078 00079 00080 00081 00082 00083 00084 00085 00086 00087 }
Generated on Mon Jul 18 2022 19:02:40 by
1.7.2
