Public Member Functions | Protected Attributes
Servo Class Reference

#include <Servo.h>

List of all members.

Public Member Functions

void calibrate (float range=0.0005, float degrees=45.0)
 operator float ()
Servooperator= (float percent)
Servooperator= (Servo &rhs)
void position (float degrees)
float read ()
 Servo (PinName pin)
void write (float percent)

Protected Attributes

float _degrees
float _p
PwmOut _pwm
float _range

Detailed Description

Servo control class, based on a PwmOut


 // Continuously sweep the servo through it's full range
 #include "mbed.h"
 #include "Servo.h"
 Servo myservo(p21);
 int main() {
     while(1) {
         for(int i=0; i<100; i++) {
             myservo = i/100.0;
         for(int i=100; i>0; i--) {
             myservo = i/100.0;

Definition at line 52 of file Servo.h.

Constructor & Destructor Documentation

Servo::Servo ( PinName  pin)

Create a servo object connected to the specified PwmOut pin

pinPwmOut pin to connect to

Member Function Documentation

void Servo::calibrate ( float  range = 0.0005,
float  degrees = 45.0 

Allows calibration of the range and angles for a particular servo

rangePulsewidth range from center (1.5ms) to maximum/minimum position in seconds
degreesAngle from centre to maximum/minimum position in degrees
Servo::operator float ( )
Servo& Servo::operator= ( float  percent)

Shorthand for the write and read functions

Servo& Servo::operator= ( Servo rhs)
void Servo::position ( float  degrees)

Set the servo position

degreesServo position in degrees
float Servo::read ( )

Read the servo motors current position

returnsA normalised number 0.0-1.0 representing the full range.
void Servo::write ( float  percent)

Set the servo position, normalised to it's full range

percentA normalised number 0.0-1.0 to represent the full range.

Member Data Documentation

float Servo::_degrees [protected]

Definition at line 94 of file Servo.h.

float Servo::_p [protected]

Definition at line 95 of file Servo.h.

PwmOut Servo::_pwm [protected]

Definition at line 92 of file Servo.h.

float Servo::_range [protected]

Definition at line 93 of file Servo.h.

The documentation for this class was generated from the following file:

Author(s): Gary Servin
autogenerated on Sat Oct 7 2017 03:08:46