/Servo-for-Atmega328p

Servo control for ATmega328p

Primary LanguageC++MIT LicenseMIT

Servo-for-Atmega328p

Simple library to control up to 12 servos on Atmega328p microcontroller.

This library uses timer 1.

Usage

Configure timer1 for Servo objects:

static void begin();

ISR functions:

static void ISRpulseA();
static void ISRpulseB();

ISRpulseA() is in TIMER1_COMPA_vect routine
ISRpulseB() is in TIMER1_COMPB_vect routine


Activate servo:

void activate(int8_t & port, int8_t & pin, int16_t angle);
  • port: i.e PORTB
  • pin i.e PB2
  • angle: Angle the servo will go to after activation

Servo will not activate if there are 12 active servos or if other servo uses given port and pin combination.


Check whether servo is active:

bool isActive();

Deactivate servo:

void deactivate();

Set hardware limits of the servo:

void setMinAngle(int16_t a);
void setMaxAngle(int16_t a);
void setMinPulse(uint16_t p);
void setMaxPulse(uint16_t p);

Set imposed limits of the servo:

void setUsableMinAngle(int16_t a);
void setUsableMaxAngle(int16_t a);

Set current angle/pulse:

void setAngle(int16_t a);
void setPulse(uint16_t p);

Get number of active servos:

static uint8_t getServoNumber();
  • returns: Number of servos that are active

Get servo's parameters:

int16_t getMinAngle();
int16_t getMaxAngle();
uint16_t getMinPulse();
uint16_t getMaxPulse();
int16_t getUsableMinAngle();
int16_t getUsableMaxAngle();
int16_t getAngle();
uint16_t getPulse();