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: VariableSpeedServo
Fork of Servo by
Servo Class Reference
Class to control servos on any pin, without using pwm Tested on Nucleo -L152RE @40MHz MCU clock and the st disco -f746ng RUNNING AT 216mhZ. More...
#include <Servo.h>
Public Member Functions | |
| Servo (PinName Pin) | |
| Create a new Servo object on any mbed pin. | |
| void | SetPosition (int NewPos) |
| Change the position of the servo. | |
| int | SpeedConvert (int _speed) |
| speed oonversion from arbitary range of 1-50 to us to set Ticker Speed rate. | |
| void | Enable (int StartPos, int RefreshRate, int _speed) |
| Enable the servo. | |
| void | Disable () |
| Disable the servo. | |
| void | Update () |
| determines direction of servo's move, called by Ticker Speed | |
Detailed Description
Class to control servos on any pin, without using pwm Tested on Nucleo -L152RE @40MHz MCU clock and the st disco -f746ng RUNNING AT 216mhZ.
Example:
// Keep sweeping two servos from left to right #include "mbed.h" #include "Servo.h" *int main() *{ Servo Servo1(D12); // create new instance of servo with output pin number Servo Servo2(D10); Servo1.Enable(1500,50,10); // Start position ; in us (1500 = center), servo refresh rate in Hz (analog servos = 50 Hz), servo movement speed range from 1-50, 1 slowest, about 20 seconds/180 degrees Servo2.Enable(1500,50,10); while(1) { Servo1.SetPosition(2300); Servo2.SetPosition(2300); wait(2.5); Servo1.SetPosition(700); Servo2.SetPosition(700); wait(2.5); } *}
Definition at line 64 of file Servo.h.
Constructor & Destructor Documentation
| Servo | ( | PinName | Pin ) |
Member Function Documentation
| void Disable | ( | ) |
| void Enable | ( | int | StartPos, |
| int | RefreshRate, | ||
| int | _speed | ||
| ) |
Enable the servo.
Without enabling the servo won't be running. Startposition and period both in us.
- Parameters:
-
StartPos The position of the servo to start (us) RefreshRate.set in Hz The time between every servo pulse. 20000 us = 50 Hz(standard) (us) Analog servos typically use a 50Hz refresh rate, while digital servos can use up to a 300Hz refresh rate. _speed The time between updating the pulse width of the servo pulses --controls speed of servo movement
| void SetPosition | ( | int | NewPos ) |
| int SpeedConvert | ( | int | _speed ) |
Generated on Sat Jul 16 2022 12:32:09 by
1.7.2
