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:
- 10:fe74e8909d3f
- Parent:
- 4:9c003c402033
- Child:
- 16:69911e81dfd4
--- a/Servo.cpp Tue Aug 31 15:38:44 2021 +0000
+++ b/Servo.cpp Thu Feb 10 12:04:36 2022 +0000
@@ -2,6 +2,10 @@
Servo::Servo(PinName Pin) : ServoPin(Pin) {}
+/**
+ * Sets the desired position.
+ * @Pos desired position in mus (position/period).
+ */
void Servo::SetPosition(int Pos)
{
Position = Pos;
@@ -10,7 +14,7 @@
void Servo::StartPulse()
{
ServoPin = 1;
- PulseStop.attach_us(callback(this, &Servo::EndPulse), Position);
+ PulseStop.attach(callback(this, &Servo::EndPulse), std::chrono::microseconds{static_cast<long int>(Position)});
}
void Servo::EndPulse()
@@ -18,12 +22,20 @@
ServoPin = 0;
}
+/**
+ * Enables the servo with start position and period.
+ * @StartPos start position in mus.
+ * @Period period in mus.
+ */
void Servo::Enable(int StartPos, int Period)
{
Position = StartPos;
- Pulse.attach_us(callback(this, &Servo::StartPulse), Period);
+ Pulse.attach(callback(this, &Servo::StartPulse), std::chrono::microseconds{static_cast<long int>(Period)});
}
+/**
+ * Disables the servo.
+ */
void Servo::Disable()
{
Pulse.detach();
