IoTKitV3 / IoTKit

Dependencies:   wifi-ism43362

Dependents:   DigitalOut DigitalOut

Embed: (wiki syntax)

« Back to documentation index

Servo Class Reference

Servo Class Reference

Servo control class, based on a PwmOut. More...

#include <Servo.h>

Public Member Functions

 Servo (PinName pin)
 Create a servo object connected to the specified PwmOut pin.
void write (float percent)
 Set the servo position, normalised to it's full range.
float read ()
 Read the servo motors current position.
Servooperator= (float percent)
 Shorthand for the write and read functions.

Detailed Description

Servo control class, based on a PwmOut.

Example:

 // Continuously sweep the servo through it's full range
 #include "mbed.h"
 #include "Servo.h"

 Servo myservo(D6);

 int main() {
     while(1) {
         for(int i=0; i<100; i++) {
             myservo = i/100.0;
             wait(0.01);
         }
         for(int i=100; i>0; i--) {
             myservo = i/100.0;
             wait(0.01);
         }
     }
 }

Definition at line 53 of file Servo.h.


Constructor & Destructor Documentation

Servo ( PinName  pin )

Create a servo object connected to the specified PwmOut pin.

Parameters:
pinPwmOut pin to connect to

Definition at line 28 of file Servo.cpp.


Member Function Documentation

Servo & operator= ( float  percent )

Shorthand for the write and read functions.

Definition at line 48 of file Servo.cpp.

float read (  )

Read the servo motors current position.

Parameters:
returnsA normalised number 0.0-1.0 representing the full range.

Definition at line 43 of file Servo.cpp.

void write ( float  percent )

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

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

Definition at line 34 of file Servo.cpp.