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

Show/hide line numbers Servo.cpp Source File

Servo.cpp

00001 #include "Servo.h"
00002 #include "mbed.h"
00003 
00004     Servo::Servo(PinName Pin) : ServoPin(Pin) {}
00005 
00006     void Servo::SetPosition(int Pos) {
00007         Position = Pos;
00008     }
00009 
00010     void Servo::StartPulse() {
00011         ServoPin = 1;
00012         PulseStop.attach_us(this, &Servo::EndPulse, Position);
00013     }
00014 
00015     void Servo::EndPulse() {
00016         ServoPin = 0;
00017     }
00018 
00019     void Servo::Enable(int StartPos, int Period) {
00020         Position = StartPos;
00021         Pulse.attach_us(this, &Servo::StartPulse, Period);
00022     }
00023 
00024     void Servo::Disable() {
00025         Pulse.detach();
00026     }