Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LSM9DS1 RangeFinder FastPWM
Dependents: PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board PM2_Example_PES_board ... more
Diff: Servo.cpp
- Revision:
- 16:69911e81dfd4
- Parent:
- 10:fe74e8909d3f
- Child:
- 18:21c0a669d6ef
--- a/Servo.cpp	Mon Mar 21 13:31:15 2022 +0000
+++ b/Servo.cpp	Mon Mar 21 13:47:46 2022 +0000
@@ -3,12 +3,12 @@
 Servo::Servo(PinName Pin) : ServoPin(Pin) {}
 
 /**
- * Sets the desired position.
- * @Pos desired position in mus (position/period).
+ * Sets the desired angle.
+ * @_Input a value between 0...1.
  */
-void Servo::SetPosition(int Pos)
+void Servo::SetPosition(float _Input)
 {
-    Position = Pos;
+    Position = static_cast<int>(_Input * static_cast<float>(Period));
 }
 
 void Servo::StartPulse()
@@ -23,13 +23,14 @@
 }
 
 /**
- * Enables the servo with start position and period.
- * @StartPos start position in mus.
- * @Period period in mus.
+ * Enables the servo with start angle and period.
+ * @_StartInput a value between 0...1.
+ * @_Period period in mus.
  */
-void Servo::Enable(int StartPos, int Period)
+void Servo::Enable(float _StartInput, int _Period)
 {
-    Position = StartPos;
+    Period = _Period;
+    Position = static_cast<int>(_StartInput * static_cast<float>(Period));
     Pulse.attach(callback(this, &Servo::StartPulse), std::chrono::microseconds{static_cast<long int>(Period)});
 }
 
    