Library to control servos

Files at this revision

API Documentation at this revision

Comitter:
Cornelius Bezuidenhout
Date:
Sat Oct 21 21:57:17 2017 +0200
Parent:
2:738b08cb03ea
Child:
4:95b334f2306c
Commit message:
Added GetMax and GetMin functions

Changed in this revision

Servo.cpp Show annotated file Show diff for this revision Revisions of this file
Servo.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/Servo.cpp	Sat Oct 21 21:36:48 2017 +0200
+++ b/Servo.cpp	Sat Oct 21 21:57:17 2017 +0200
@@ -1,5 +1,3 @@
-
-
 #include "Servo.hpp"
 
 Servo::Servo(PinName pwmPin, float zeroAngle, float minAngle, float maxAngle) :
@@ -25,15 +23,9 @@
     _servo.pulsewidth(pw);
 }
 
-void Servo::SaveZero()
-{
-    ZEROPW = (ZEROPW+_angle*PW_PER_DEG);
-}
+void Servo::SaveZero() { ZEROPW = (ZEROPW+_angle*PW_PER_DEG); }
 
-void Servo::Calibrate(float actualAngle)
-{
-    PW_PER_DEG = (_angle*PW_PER_DEG)/actualAngle;
-}
+void Servo::Calibrate(float actualAngle) { PW_PER_DEG = (_angle*PW_PER_DEG)/actualAngle; }
 
 void Servo::Set(float angle)
 {
@@ -61,19 +53,11 @@
     SetServo();
 }
 
-void Servo::SetZero(float angle)
-{
-  ZEROPW = (ZEROPW+angle*PW_PER_DEG);
-}
+void Servo::SetZero(float angle) { ZEROPW = (ZEROPW+angle*PW_PER_DEG); }
 
-void Servo::Off()
-{
-    _servo.pulsewidth(0);
-}
+void Servo::Off() { _servo.pulsewidth(0); }
 
-float Servo::GetAngle() {
-    return _angle;   
-}
+float Servo::GetAngle() { return _angle; }
 
 void Servo::GotoMin() {
     _angle = _minAngle;  
@@ -83,4 +67,7 @@
 void Servo::GotoMax() {
     _angle = _maxAngle;
     SetServo();
-}
\ No newline at end of file
+}
+
+void Servo::GetMin() { returns _minAngle; }
+void Servo::GetMax() { returns _maxAngle; }
\ No newline at end of file
--- a/Servo.hpp	Sat Oct 21 21:36:48 2017 +0200
+++ b/Servo.hpp	Sat Oct 21 21:57:17 2017 +0200
@@ -32,7 +32,7 @@
   
     /**
      * Calibrate the servo
-     * @param actualAngle : The actual angle from zero, of the current position in degrees.
+     * @param actualAngle : The actual angle from zero of the current position in degrees.
      */
     void Calibrate(float actualAngle);
   
@@ -81,6 +81,18 @@
      */
     void GotoMax();
 
+    /**
+     * Gets the current minimum angle of the servo
+     * @returns Minimum angle of servo
+     */
+    float GetMin();
+
+    /**
+     * Gets the current maximum angle of the servo
+     * @returns Maximum angle of servo
+     */
+    float GetMax();
+
 private:
     PwmOut _servo;
     float _angle;