Cornelius Bezuidenhout / ServoController
Revision:
1:1b8a9e5b178d
Parent:
0:1703d29e0899
Child:
2:92d4dc70d591
--- a/ServoController.hpp	Tue Sep 06 18:05:38 2016 +0000
+++ b/ServoController.hpp	Tue Sep 06 22:10:01 2016 +0200
@@ -0,0 +1,37 @@
+#ifndef SERVOCONTROLLER_H
+#define SERVOCONTROLLER_H
+
+//Includes
+#include "mbed.h"
+
+/**
+ * A Servo controller library
+ *
+ * @author CA Bezuidenhout
+ * @section USAGE EXAMPLE
+ */
+class ServoController
+{
+public:
+  /**
+   * @param pwmPin : PWM pin of servo
+   * @param ref : Reference angle in degress (default 90)
+   */
+  ServoController(PinName pwmPin, float ref = 90.0f);
+
+  /**
+   * @return The current angle of the servo
+   */
+  float GetAngle();
+
+private:
+  PWMOut _servo;
+  float _angle;
+  float _ref;
+  static const float DEG2PW = (2.0f-1.0f)/180.0f;
+
+  void SetServo();
+  void SetAbsolute(float angle);
+};
+
+#endif