PM2_Lib
Dependencies: LSM9DS1 RangeFinder FastPWM
Diff: Servo.cpp
- Revision:
- 20:ea222b81350e
- Parent:
- 19:518ed284d98b
- Child:
- 21:45d903d986f6
--- a/Servo.cpp Tue Mar 22 08:35:07 2022 +0000 +++ b/Servo.cpp Tue Mar 22 09:43:13 2022 +0000 @@ -3,7 +3,12 @@ const float Servo::MIN_INPUT = 0.01f; const float Servo::MAX_INPUT = 0.99f; -Servo::Servo(PinName Pin) : ServoPin(Pin) {} +Servo::Servo(PinName Pin) : ServoPin(Pin) +{ + servoEnabled = false; + Position = 0; + Period = 0; +} /** * Sets the desired angle. @@ -11,9 +16,11 @@ */ void Servo::SetPosition(float _Input) { - if (_Input < MIN_INPUT) _Input = MIN_INPUT; - if (_Input > MAX_INPUT) _Input = MAX_INPUT; - Position = static_cast<int>(_Input * static_cast<float>(Period)); + if (servoEnabled) { + if (_Input < MIN_INPUT) _Input = MIN_INPUT; + if (_Input > MAX_INPUT) _Input = MAX_INPUT; + Position = static_cast<int>(_Input * static_cast<float>(Period)); + } } void Servo::StartPulse() @@ -34,6 +41,7 @@ */ void Servo::Enable(float _StartInput, int _Period) { + servoEnabled = true; if (_StartInput < MIN_INPUT) _StartInput = MIN_INPUT; if (_StartInput > MAX_INPUT) _StartInput = MAX_INPUT; Period = _Period; @@ -46,5 +54,15 @@ */ void Servo::Disable() { + servoEnabled = false; Pulse.detach(); +} + +/** + * Returns true if Servo is enabled. + * @return isEnable. + */ +bool Servo::isEnabled() +{ + return servoEnabled; } \ No newline at end of file