NOT FINISHED YET!!! My first try to get a self built fully working Quadrocopter based on an mbed, a self built frame and some other more or less cheap parts.

Dependencies:   mbed MODI2C

Servo/Servo.cpp

Committer:
maetugr
Date:
2014-02-14
Revision:
40:2ca410923691
Parent:
29:8b7362a2ee14

File content as of revision 40:2ca410923691:

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

Servo::Servo(PinName Pin) : ServoPin(Pin) {
    initialize(); // TODO: Works?
}

void Servo::initialize() {
    // initialize ESC
    Enable(1000,20000); // low throttle 50Hz TODO: Frequency modify
}

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

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

void Servo::EndPulse() {
    // my change
    PulseStop.detach();
    // my change
    ServoPin = 0;
}

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

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

void Servo::operator=(int position) {
    SetPosition(position);
}