David Garrsion / VarSpeedServo

Dependents:   VariableSpeedServo

Fork of Servo by Jasper Denkers

Embed: (wiki syntax)

« Back to documentation index

Servo Class Reference

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 )

Create a new Servo object on any mbed pin.

Parameters:
PinPin on mbed to connect servo to

Definition at line 4 of file Servo.cpp.


Member Function Documentation

void Disable (  )

Disable the servo.

After disabling the servo won't get any signal anymore

Definition at line 63 of file Servo.cpp.

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:
StartPosThe position of the servo to start (us)
RefreshRate.setin 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

Definition at line 52 of file Servo.cpp.

void SetPosition ( int  NewPos )

Change the position of the servo.

Position in us

Parameters:
NewPosThe new value of the servos position (us)

Definition at line 18 of file Servo.cpp.

int SpeedConvert ( int  _speed )

speed oonversion from arbitary range of 1-50 to us to set Ticker Speed rate.

used in Enable function

Definition at line 6 of file Servo.cpp.

void Update (  )

determines direction of servo's move, called by Ticker Speed

Definition at line 23 of file Servo.cpp.