A library to control a CYS S8218 servo

Dependents:   Heiko

Files at this revision

API Documentation at this revision

Comitter:
Kerneels Bezuidenhout
Date:
Fri Sep 23 03:01:18 2016 +0200
Parent:
1:c42f4b73e85c
Child:
3:b0a7d93e2611
Commit message:
Added SetZero function

Changed in this revision

CYS8218Controller.cpp Show annotated file Show diff for this revision Revisions of this file
CYS8218Controller.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/CYS8218Controller.cpp	Wed Sep 07 03:07:07 2016 +0200
+++ b/CYS8218Controller.cpp	Fri Sep 23 03:01:18 2016 +0200
@@ -7,7 +7,11 @@
   ZEROPW = 0.0015f; //1500us default position
   PW_PER_DEG = 0.0005f/45.0f; //500us -> 45deg default
   _servo.period_us(5000);
-  SetServo();
+
+  if( initAngle != -1 )
+    SetServo();
+  else
+    _servo.pulsewidth(0);
 }
 
 void CYS8218Controller::SetServo()
@@ -40,3 +44,8 @@
   _angle += relAngle;
   SetServo();
 }
+
+void CYS8218Controller::SetZero(float angle)
+{
+  ZEROPW = (ZERO+angle*PW_PER_DEG);
+}
--- a/CYS8218Controller.hpp	Wed Sep 07 03:07:07 2016 +0200
+++ b/CYS8218Controller.hpp	Fri Sep 23 03:01:18 2016 +0200
@@ -24,6 +24,13 @@
   void SaveZero();
 
   /**
+   * Sets the zero position without moving the servo
+   *
+   * @param angle : The angle to set as the zero position
+   */
+  void SetZero(float angle);
+
+  /**
    * Calibrate the servo
    * @param actualAngle : The actual angle from zero, of the current position in degrees.
    */