Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Servo/Servo.cpp
- Committer:
- maetugr
- Date:
- 2012-10-15
- Revision:
- 7:9d4313510646
- Parent:
- 1:5a64632b1eb9
- Child:
- 9:4e0c3936c756
File content as of revision 7:9d4313510646:
#include "Servo.h"
#include "mbed.h"
Servo::Servo(PinName Pin) : ServoPin(Pin) {
}
void Servo::initialize() {
// initialize ESC
Enable(2000,20000); // full throttle
wait(0.01); // for 0.01 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);
}
