Cornelius Bezuidenhout / ServoController

ServoController.hpp

Committer:
Kerneels Bezuidenhout
Date:
2016-09-06
Revision:
1:1b8a9e5b178d
Parent:
0:1703d29e0899
Child:
2:92d4dc70d591

File content as of revision 1:1b8a9e5b178d:

#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