Library for interfacing with the NXP PCA9685 PWM controller over an I2C connection. Designed with the Adafruit breakout board (of the same name) in mind.

Dependents:   Hexapod_Library main_robot_gant_v22

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCA9685.h Source File

PCA9685.h

00001 #ifndef PCA9685_LIBRARY_H
00002 #define PCA9685_LIBRARY_H
00003 
00004 #include "mbed.h"
00005 #include "definitions.h"
00006 
00007 
00008 class PCA9685 {
00009     
00010     public:
00011         PCA9685(uint8_t i2c_addr, I2C i2c_object, float frequency);
00012         void init(void);
00013         void set_pwm_output(int pwm_output, uint16_t count_on, uint16_t count_off);
00014         void set_pwm_output_on_0(int pwm_output, uint16_t count_off);
00015         void set_pwm_duty(int pwm_output, float duty_cycle);
00016         void set_pwm_pw(int pwm_output, float pulse_width_us);
00017         void update(void);
00018         
00019     private: 
00020         void reset(void);
00021         void write_8(uint8_t reg, uint8_t msg);
00022         uint8_t read_8(uint8_t reg);
00023         void set_prescale(uint8_t prescale);
00024         int convert_pwm_value(float pulse_width_us, float period_us);
00025     
00026     private:
00027         int i2c_addr;
00028         float freq;
00029         I2C i2c;
00030 };        
00031 
00032 #endif