PCA9685 library
Dependents: s-rov-firmware DISCO-F746NG_rtos_test
Diff: pca9685.h
- Revision:
- 0:c6fb5a9a8f91
- Child:
- 1:7e071acc57b1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pca9685.h Mon Jan 16 04:54:27 2017 +0000 @@ -0,0 +1,45 @@ +#ifndef _PCA9685_H_ +#define _PCA9685_H_ + +#include "mbed.h" + +#define PCA9685_MODE1 0x00 +#define PCA9685_MODE2 0x01 +#define PCA9685_PRESCALE 0xFE +#define PCA9685_LED0_ON_L 0x06 +#define PCA9685_CLOCK 25000000 + +#define CH_LED1 2 +#define CH_LED2 3 +#define CH_ESC1 4 +#define CH_ESC2 5 +#define CH_ESC3 6 +#define CH_ESC4 7 +#define CH_1 11 +#define CH_2 10 +#define CH_3 9 +#define CH_4 8 +#define CH_5 0 +#define CH_6 1 + + +class PCA9685{ + public: + PCA9685(uint8_t i2c_addr, I2C i2c_object, float freq); + void reset(void); + void init(void); + void set_pwm_frequency(float freq); + void set_pwm_output(uint8_t num, uint16_t on, uint16_t off); + void set_pwm_duty(uint8_t num, float duty); + void set_servo_angle(uint8_t num, float angle); + void write_8(uint8_t reg, uint8_t msg); + char read_8(uint8_t reg); + + private: + uint8_t PCA9685_ADDR; + float frequency; + I2C i2c; + +}; + +#endif \ No newline at end of file