A servo library for controlling servos without using PWM. Can be used on any pin.

Dependents:   ServoTest ServoTest Nucleo_coffee NervousPuppySprintOne ... more

Embed: (wiki syntax)

« Back to documentation index

Servo Class Reference

Servo Class Reference

Class to control a servo on any pin, without using pwm. 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.
void Enable (int StartPos, int Period)
 Enable the servo.
void Disable ()
 Disable the servo.

Detailed Description

Class to control a servo on any pin, without using pwm.

Example:

 // Keep sweeping servo from left to right
 #include "mbed.h"
 #include "Servo.h"
 
 Servo Servo1(p20);

 Servo1.Enable(1500,20000);

 while(1) {
     for (int pos = 1000; pos < 2000; pos += 25) {
         Servo1.SetPosition(pos);  
         wait_ms(20);
     }
     for (int pos = 2000; pos > 1000; pos -= 25) {
         Servo1.SetPosition(pos); 
         wait_ms(20); 
     }
 }

Definition at line 53 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 24 of file Servo.cpp.

void Enable ( int  StartPos,
int  Period 
)

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)
PeriodThe time between every pulse. 20000 us = 50 Hz(standard) (us)

Definition at line 19 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 6 of file Servo.cpp.