Jan Kamidra / Servo
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(callback(this, &Servo::EndPulse), std::chrono::microseconds(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(callback(this, &Servo::StartPulse), std::chrono::microseconds(Period));
00022     }
00023 
00024     void Servo::Disable() {
00025         Pulse.detach();
00026     }