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+
Revision 2:2f6d7872d6f3, committed 2022-06-10
- Comitter:
- JohnnyK
- Date:
- Fri Jun 10 04:22:15 2022 +0000
- Parent:
- 1:352133517ccc
- Commit message:
- First release under MbedOS6+
Changed in this revision
| Servo.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Servo.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Servo.cpp Sun Oct 17 13:34:19 2010 +0000
+++ b/Servo.cpp Fri Jun 10 04:22:15 2022 +0000
@@ -9,7 +9,7 @@
void Servo::StartPulse() {
ServoPin = 1;
- PulseStop.attach_us(this, &Servo::EndPulse, Position);
+ PulseStop.attach(callback(this, &Servo::EndPulse), std::chrono::microseconds(Position));
}
void Servo::EndPulse() {
@@ -18,7 +18,7 @@
void Servo::Enable(int StartPos, int Period) {
Position = StartPos;
- Pulse.attach_us(this, &Servo::StartPulse, Period);
+ Pulse.attach(callback(this, &Servo::StartPulse), std::chrono::microseconds(Period));
}
void Servo::Disable() {
--- a/Servo.h Sun Oct 17 13:34:19 2010 +0000
+++ b/Servo.h Fri Jun 10 04:22:15 2022 +0000
@@ -1,5 +1,6 @@
/* mbed Servo Library without using PWM pins
* Copyright (c) 2010 Jasper Denkers
+ * Copyright (c) 2022 Jan Kamidra
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -20,8 +21,8 @@
* THE SOFTWARE.
*/
-#ifndef MBED_SERVO_H
-#define MBED_SERVO_H
+#ifndef SERVO_H
+#define SERVO_H
#include "mbed.h"
@@ -40,11 +41,11 @@
* while(1) {
* for (int pos = 1000; pos < 2000; pos += 25) {
* Servo1.SetPosition(pos);
- * wait_ms(20);
+ * thread_sleep_for(20);
* }
* for (int pos = 2000; pos > 1000; pos -= 25) {
* Servo1.SetPosition(pos);
- * wait_ms(20);
+ * thread_sleep_for(20);
* }
* }
* @endcode
Jan Kamidra