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.
You are viewing an older revision! See the latest version
Projekt Servo
In RC Servo's you set the position based on duty cycle or pulse width of the pwm signal.
This example code uses a period of 0.020s and increases the pulse width by 0.0001s on each pass. This will cause an increase of .5% of the servo's range every .25s. In effect the servo will move 2% of its range per second, meaning after 50 seconds the servo will have gone from 0% to 100% of its range.
#include "mbed.h" PwmOut servo(p21); int main() { servo.period(0.020); // servo requires a 20ms period while (1) { for(float offset=0.0; offset<0.001; offset+=0.0001) { servo.pulsewidth(0.001 + offset); // servo position determined by a pulsewidth between 1-2ms wait(0.25); } } }
Untersuchen Sie folgende Mbed-Bibliothek.
Servo myservo(P0_8); myservo.calibrate(range, 45.0); myservo = position; wait_ms(500);