A servo library for controlling servos without using PWM. Can be used on any pin.
Dependents: ServoTest ServoTest Nucleo_coffee NervousPuppySprintOne ... more
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_us(this, &Servo::EndPulse, 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_us(this, &Servo::StartPulse, Period); 00022 } 00023 00024 void Servo::Disable() { 00025 Pulse.detach(); 00026 }
Generated on Tue Jul 12 2022 12:33:04 by 1.7.2