A very simple wrapper around the PWM library.
Dependents: JS_1motor_20170707_ok Task_1_BallRidingbot_KeepingStationCatching_layingDown_1230 Task_2_BallRidingbot_MovingForwardCatching_backward_1230 testSSWMR_StationKeeping_200170830_OK ... more
This is my own wrapper around the PWM library. It handles servos with very long pulse intervals much better. It doesn't HAVE to be used with a servo, but I'm not too sure what else you could use it for. In any case, you're welcome to use it for whatever purpose you want.
Example code is shown below:
#include "mbed.h" #include "Servo.h" Servo servo(p26); int main(void) { // .calibrate(pulse interval, minimum pulse width, maximum pulse width) servo.calibrate(0.02, 0.05*0.02, 0.10*0.02); float val = 0.0; while(1) { servo.write(val); val = val < 1.0 ? val + 0.1 : 0; wait(1); } }
Revision 2:4c315bcd91b4, committed 2013-02-15
- Comitter:
- andrewrussell
- Date:
- Fri Feb 15 05:16:58 2013 +0000
- Parent:
- 1:c1b2ec2662fd
- Commit message:
- Fixed the bug that the bug fix created.
Changed in this revision
Servo.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c1b2ec2662fd -r 4c315bcd91b4 Servo.cpp --- a/Servo.cpp Fri Feb 15 05:14:48 2013 +0000 +++ b/Servo.cpp Fri Feb 15 05:16:58 2013 +0000 @@ -53,7 +53,7 @@ * @param float max Maximum pulse width in seconds * @param float min Minimum pulse width in seconds */ -void Servo::calibrate(float period, float min, float min) { +void Servo::calibrate(float period, float min, float max) { _period = period; _min = min; _max = max;