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

Dependents:   ServoTest ServoTest Nucleo_coffee NervousPuppySprintOne ... more

Servo.cpp

Committer:
jdenkers
Date:
2010-10-17
Revision:
1:352133517ccc
Parent:
0:30b972d2dcec

File content as of revision 1:352133517ccc:

#include "Servo.h"
#include "mbed.h"

    Servo::Servo(PinName Pin) : ServoPin(Pin) {}

    void Servo::SetPosition(int Pos) {
        Position = Pos;
    }

    void Servo::StartPulse() {
        ServoPin = 1;
        PulseStop.attach_us(this, &Servo::EndPulse, Position);
    }

    void Servo::EndPulse() {
        ServoPin = 0;
    }

    void Servo::Enable(int StartPos, int Period) {
        Position = StartPos;
        Pulse.attach_us(this, &Servo::StartPulse, Period);
    }

    void Servo::Disable() {
        Pulse.detach();
    }