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.
PCA9685.h@5:d44f88fa27a1, 2019-06-22 (annotated)
- Committer:
- dimavb
- Date:
- Sat Jun 22 17:24:38 2019 +0000
- Revision:
- 5:d44f88fa27a1
- Parent:
- 3:a3410f2f061d
init
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el13cj | 0:aa965d6b1f8f | 1 | #ifndef PCA9685_LIBRARY_H |
el13cj | 0:aa965d6b1f8f | 2 | #define PCA9685_LIBRARY_H |
el13cj | 0:aa965d6b1f8f | 3 | |
el13cj | 0:aa965d6b1f8f | 4 | #include "mbed.h" |
el13cj | 0:aa965d6b1f8f | 5 | #include "definitions.h" |
el13cj | 0:aa965d6b1f8f | 6 | |
el13cj | 0:aa965d6b1f8f | 7 | |
el13cj | 0:aa965d6b1f8f | 8 | class PCA9685 { |
el13cj | 0:aa965d6b1f8f | 9 | |
el13cj | 0:aa965d6b1f8f | 10 | public: |
dimavb | 5:d44f88fa27a1 | 11 | PCA9685(uint8_t i2c_addr, I2C *i2c_object, float frequency); |
el13cj | 0:aa965d6b1f8f | 12 | void init(void); |
el13cj | 0:aa965d6b1f8f | 13 | void set_pwm_output(int pwm_output, uint16_t count_on, uint16_t count_off); |
el13cj | 3:a3410f2f061d | 14 | void set_pwm_output_on_0(int pwm_output, uint16_t count_off); |
el13cj | 0:aa965d6b1f8f | 15 | void set_pwm_duty(int pwm_output, float duty_cycle); |
el13cj | 0:aa965d6b1f8f | 16 | void set_pwm_pw(int pwm_output, float pulse_width_us); |
el13cj | 0:aa965d6b1f8f | 17 | void update(void); |
el13cj | 0:aa965d6b1f8f | 18 | |
el13cj | 0:aa965d6b1f8f | 19 | private: |
el13cj | 0:aa965d6b1f8f | 20 | void reset(void); |
el13cj | 0:aa965d6b1f8f | 21 | void write_8(uint8_t reg, uint8_t msg); |
el13cj | 0:aa965d6b1f8f | 22 | uint8_t read_8(uint8_t reg); |
el13cj | 0:aa965d6b1f8f | 23 | void set_prescale(uint8_t prescale); |
el13cj | 0:aa965d6b1f8f | 24 | int convert_pwm_value(float pulse_width_us, float period_us); |
el13cj | 0:aa965d6b1f8f | 25 | |
el13cj | 0:aa965d6b1f8f | 26 | private: |
el13cj | 0:aa965d6b1f8f | 27 | int i2c_addr; |
el13cj | 0:aa965d6b1f8f | 28 | float freq; |
dimavb | 5:d44f88fa27a1 | 29 | I2C *i2c; |
el13cj | 0:aa965d6b1f8f | 30 | }; |
el13cj | 0:aa965d6b1f8f | 31 | |
el13cj | 0:aa965d6b1f8f | 32 | #endif |