Servo library based on Timer instead of PWM. Fork of original https://os.mbed.com/users/jdenkers/code/Servo/ and modified for compatibility with MbedOS6+
Servo.cpp@0:30b972d2dcec, 2010-10-17 (annotated)
- Committer:
- jdenkers
- Date:
- Sun Oct 17 13:13:50 2010 +0000
- Revision:
- 0:30b972d2dcec
- Child:
- 2:2f6d7872d6f3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jdenkers | 0:30b972d2dcec | 1 | #include "Servo.h" |
jdenkers | 0:30b972d2dcec | 2 | #include "mbed.h" |
jdenkers | 0:30b972d2dcec | 3 | |
jdenkers | 0:30b972d2dcec | 4 | Servo::Servo(PinName Pin) : ServoPin(Pin) {} |
jdenkers | 0:30b972d2dcec | 5 | |
jdenkers | 0:30b972d2dcec | 6 | void Servo::SetPosition(int Pos) { |
jdenkers | 0:30b972d2dcec | 7 | Position = Pos; |
jdenkers | 0:30b972d2dcec | 8 | } |
jdenkers | 0:30b972d2dcec | 9 | |
jdenkers | 0:30b972d2dcec | 10 | void Servo::StartPulse() { |
jdenkers | 0:30b972d2dcec | 11 | ServoPin = 1; |
jdenkers | 0:30b972d2dcec | 12 | PulseStop.attach_us(this, &Servo::EndPulse, Position); |
jdenkers | 0:30b972d2dcec | 13 | } |
jdenkers | 0:30b972d2dcec | 14 | |
jdenkers | 0:30b972d2dcec | 15 | void Servo::EndPulse() { |
jdenkers | 0:30b972d2dcec | 16 | ServoPin = 0; |
jdenkers | 0:30b972d2dcec | 17 | } |
jdenkers | 0:30b972d2dcec | 18 | |
jdenkers | 0:30b972d2dcec | 19 | void Servo::Enable(int StartPos, int Period) { |
jdenkers | 0:30b972d2dcec | 20 | Position = StartPos; |
jdenkers | 0:30b972d2dcec | 21 | Pulse.attach_us(this, &Servo::StartPulse, Period); |
jdenkers | 0:30b972d2dcec | 22 | } |
jdenkers | 0:30b972d2dcec | 23 | |
jdenkers | 0:30b972d2dcec | 24 | void Servo::Disable() { |
jdenkers | 0:30b972d2dcec | 25 | Pulse.detach(); |
jdenkers | 0:30b972d2dcec | 26 | } |