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@2:2f6d7872d6f3, 2022-06-10 (annotated)
- Committer:
- JohnnyK
- Date:
- Fri Jun 10 04:22:15 2022 +0000
- Revision:
- 2:2f6d7872d6f3
- Parent:
- 0:30b972d2dcec
First release under MbedOS6+
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; |
JohnnyK | 2:2f6d7872d6f3 | 12 | PulseStop.attach(callback(this, &Servo::EndPulse), std::chrono::microseconds(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; |
JohnnyK | 2:2f6d7872d6f3 | 21 | Pulse.attach(callback(this, &Servo::StartPulse), std::chrono::microseconds(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 | } |