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.
Diff: Servo/Servo.cpp
- Revision:
- 0:0c4fafa398b4
- Child:
- 1:5a64632b1eb9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo/Servo.cpp Wed Sep 26 12:15:00 2012 +0000 @@ -0,0 +1,35 @@ +#include "Servo.h" +#include "mbed.h" + +Servo::Servo(PinName Pin) : ServoPin(Pin) { + // initialize ESC + Enable(2000,20000); // full throttle + wait(2); // for 2 secs + SetPosition(1000); // low throttle +} + +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(); +} + +void Servo::operator=(int position) { + SetPosition(position); +} \ No newline at end of file