servo publish

Dependents:   TurtleBot_v01 TurtleBot_with_AHS

Fork of Servo by Jasper Denkers

Servo.cpp

Committer:
worasuchad
Date:
2018-08-13
Revision:
2:895102af6679
Parent:
0:30b972d2dcec

File content as of revision 2:895102af6679:

#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();
    }