COSA
An Object-Oriented Platform for Arduino Programming
Servo.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_SERVO_HH
22 #define COSA_SERVO_HH
23 
24 #include "Cosa/Types.h"
25 #include "Cosa/OutputPin.hh"
26 
34 class Servo : private OutputPin {
35 public:
42  Servo(uint8_t ix, Board::DigitalPin pin) :
43  OutputPin(pin),
44  m_min(MIN_WIDTH),
45  m_max(MAX_WIDTH)
46  {
47  angle(INIT_ANGLE);
48  servo[ix != 0] = this;
49  }
50 
54  static bool begin();
55 
59  static bool end();
60 
67  void pulse(uint16_t min, uint16_t max)
68  __attribute__((always_inline))
69  {
70  m_min = min;
71  m_max = max;
72  }
73 
78  uint16_t width() const
79  {
80  return (m_width);
81  }
82 
87  void angle(uint8_t degree);
88 
93  uint8_t angle() const
94  {
95  return (m_angle);
96  }
97 
98 private:
100  static const uint16_t PERIOD = 20000;
101  static const uint16_t MIN_WIDTH = 650;
102  static const uint16_t MAX_WIDTH = 2300;
103  static const uint8_t INIT_ANGLE = 90;
104 
106  static Servo* servo[2];
107 
111  uint16_t m_min;
112  uint16_t m_max;
113  uint16_t m_width;
114  uint8_t m_angle;
115 
117  friend void TIMER1_COMPA_vect(void);
118  friend void TIMER1_COMPB_vect(void);
119 };
120 
121 #endif
uint8_t pin() const
Definition: Pin.hh:103
friend void TIMER1_COMPB_vect(void)
static bool begin()
Definition: Servo.cpp:30
Servo(uint8_t ix, Board::DigitalPin pin)
Definition: Servo.hh:42
uint16_t width() const
Definition: Servo.hh:78
uint8_t angle() const
Definition: Servo.hh:93
static bool end()
Definition: Servo.cpp:43
void pulse(uint16_t min, uint16_t max)
Definition: Servo.hh:67
friend void TIMER1_COMPA_vect(void)
Definition: Servo.hh:34