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
- Committer:
- JohnnyK
- Date:
- 2022-06-10
- Revision:
- 2:2f6d7872d6f3
- Parent:
- 0:30b972d2dcec
File content as of revision 2:2f6d7872d6f3:
#include "Servo.h" #include "mbed.h" Servo::Servo(PinName Pin) : ServoPin(Pin) {} void Servo::SetPosition(int Pos) { Position = Pos; } void Servo::StartPulse() { ServoPin = 1; PulseStop.attach(callback(this, &Servo::EndPulse), std::chrono::microseconds(Position)); } void Servo::EndPulse() { ServoPin = 0; } void Servo::Enable(int StartPos, int Period) { Position = StartPos; Pulse.attach(callback(this, &Servo::StartPulse), std::chrono::microseconds(Period)); } void Servo::Disable() { Pulse.detach(); }