COSA
An Object-Oriented Platform for Arduino Programming
Servo Class Reference

#include <Servo.hh>

Inheritance diagram for Servo:
Inheritance graph
Collaboration diagram for Servo:
Collaboration graph

Public Member Functions

 Servo (uint8_t ix, Board::DigitalPin pin)
 
void pulse (uint16_t min, uint16_t max)
 
uint16_t width () const
 
void angle (uint8_t degree)
 
uint8_t angle () const
 

Static Public Member Functions

static bool begin ()
 
static bool end ()
 

Private Types

enum  Direction { MSB_FIRST = 0, LSB_FIRST = 1 }
 

Private Member Functions

void _set () const
 
void _set (int value) const
 
void set () const
 
void set (int value) const
 
void high () const
 
void on () const
 
void _clear () const
 
void clear () const
 
void low () const
 
void off () const
 
void _toggle () const
 
void toggle () const
 
void _write (int value) const
 
void write (int value) const
 
void write (uint8_t value, OutputPin &clk, Direction order=MSB_FIRST) const
 
void write (uint16_t value, uint8_t bits, uint16_t us) const
 
OutputPinoperator<< (int value)
 
void pulse (uint16_t us) const
 
volatile uint8_t * PIN () const
 
volatile uint8_t * DDR () const
 
volatile uint8_t * PORT () const
 
uint8_t pin () const
 
bool is_set () const
 
bool is_high () const
 
bool is_on () const
 
bool is_clear () const
 
bool is_low () const
 
bool is_off () const
 
bool read () const
 
uint8_t read (OutputPin &clk, Direction order=MSB_FIRST) const
 
 operator bool () const
 
Pinoperator>> (uint8_t &var)
 
volatile uint8_t * PCIMR () const
 

Static Private Member Functions

static void mode (Board::DigitalPin pin, uint8_t initial=0)
 
static void toggle (Board::DigitalPin pin)
 
static void _write (Board::DigitalPin pin, uint8_t value)
 
static void write (Board::DigitalPin pin, int value)
 
static uint8_t MASK (uint8_t pin)
 
static volatile uint8_t * PIN (uint8_t pin)
 
static volatile uint8_t * DDR (uint8_t pin)
 
static volatile uint8_t * PORT (uint8_t pin)
 
static bool read (Board::DigitalPin pin)
 

Private Attributes

volatile uint8_t *const m_sfr
 
const uint8_t m_mask
 
const uint8_t m_pin
 

Friends

void TIMER1_COMPA_vect (void)
 
void TIMER1_COMPB_vect (void)
 

Detailed Description

Servo motor driver. Uses Timer#1 and the two compare output registers.

Limitations

Cannot be used together with other classes that use Timer#1.

Definition at line 34 of file Servo.hh.

Constructor & Destructor Documentation

Servo::Servo ( uint8_t  ix,
Board::DigitalPin  pin 
)
inline

Construct a servo instance connected to the given pin. Default angle is 90 degree.

Parameters
[in]ixindex of servo [0..1].
[in]pindigital pin to use as servo control output pin.

Definition at line 42 of file Servo.hh.

Member Function Documentation

void Servo::angle ( uint8_t  degree)

Set servo to given angle degree.

Parameters
[in]degreeangle, 0..180.

Definition at line 51 of file Servo.cpp.

uint8_t Servo::angle ( ) const
inline

Return servo angle.

Returns
angle in degree, 0..180.

Definition at line 93 of file Servo.hh.

bool Servo::begin ( )
static

Start servo controller; enable interrupt handlers.

Definition at line 30 of file Servo.cpp.

bool Servo::end ( )
static

Stop servo controller; disable interrupt handlers.

Definition at line 43 of file Servo.cpp.

void Servo::pulse ( uint16_t  min,
uint16_t  max 
)
inline

Set pulse limits; min and max number of micro seconds. These will correspond to angle 0 and 180.

Parameters
[in]minnumber of micro seconds.
[in]maxnumber of micro seconds.

Definition at line 67 of file Servo.hh.

uint16_t Servo::width ( ) const
inline

Return current pulse width in micro seconds.

Returns
pulse width.

Definition at line 78 of file Servo.hh.

Friends And Related Function Documentation

void TIMER1_COMPA_vect ( void  )
friend

Interrupt Service Routines.

void TIMER1_COMPB_vect ( void  )
friend

The documentation for this class was generated from the following files: