PCA9685 library
Dependents: s-rov-firmware DISCO-F746NG_rtos_test
pca9685.h@2:5c8802f876f8, 2017-01-26 (annotated)
- Committer:
- YJ_Kim
- Date:
- Thu Jan 26 17:04:46 2017 +0000
- Revision:
- 2:5c8802f876f8
- Parent:
- 1:7e071acc57b1
Change i2c object to pointer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
YJ_Kim | 0:c6fb5a9a8f91 | 1 | #ifndef _PCA9685_H_ |
YJ_Kim | 0:c6fb5a9a8f91 | 2 | #define _PCA9685_H_ |
YJ_Kim | 0:c6fb5a9a8f91 | 3 | |
YJ_Kim | 0:c6fb5a9a8f91 | 4 | #include "mbed.h" |
YJ_Kim | 0:c6fb5a9a8f91 | 5 | |
YJ_Kim | 0:c6fb5a9a8f91 | 6 | #define PCA9685_MODE1 0x00 |
YJ_Kim | 0:c6fb5a9a8f91 | 7 | #define PCA9685_MODE2 0x01 |
YJ_Kim | 0:c6fb5a9a8f91 | 8 | #define PCA9685_PRESCALE 0xFE |
YJ_Kim | 0:c6fb5a9a8f91 | 9 | #define PCA9685_LED0_ON_L 0x06 |
YJ_Kim | 0:c6fb5a9a8f91 | 10 | #define PCA9685_CLOCK 25000000 |
YJ_Kim | 0:c6fb5a9a8f91 | 11 | |
YJ_Kim | 0:c6fb5a9a8f91 | 12 | class PCA9685{ |
YJ_Kim | 0:c6fb5a9a8f91 | 13 | public: |
YJ_Kim | 2:5c8802f876f8 | 14 | PCA9685(uint8_t i2c_addr, I2C* i2c_object, float freq); |
YJ_Kim | 0:c6fb5a9a8f91 | 15 | void reset(void); |
YJ_Kim | 0:c6fb5a9a8f91 | 16 | void init(void); |
YJ_Kim | 0:c6fb5a9a8f91 | 17 | void set_pwm_frequency(float freq); |
YJ_Kim | 0:c6fb5a9a8f91 | 18 | void set_pwm_output(uint8_t num, uint16_t on, uint16_t off); |
YJ_Kim | 0:c6fb5a9a8f91 | 19 | void set_pwm_duty(uint8_t num, float duty); |
YJ_Kim | 0:c6fb5a9a8f91 | 20 | void set_servo_angle(uint8_t num, float angle); |
YJ_Kim | 0:c6fb5a9a8f91 | 21 | void write_8(uint8_t reg, uint8_t msg); |
YJ_Kim | 0:c6fb5a9a8f91 | 22 | char read_8(uint8_t reg); |
YJ_Kim | 0:c6fb5a9a8f91 | 23 | |
YJ_Kim | 0:c6fb5a9a8f91 | 24 | private: |
YJ_Kim | 0:c6fb5a9a8f91 | 25 | uint8_t PCA9685_ADDR; |
YJ_Kim | 0:c6fb5a9a8f91 | 26 | float frequency; |
YJ_Kim | 2:5c8802f876f8 | 27 | I2C* i2c; |
YJ_Kim | 0:c6fb5a9a8f91 | 28 | |
YJ_Kim | 0:c6fb5a9a8f91 | 29 | }; |
YJ_Kim | 0:c6fb5a9a8f91 | 30 | |
YJ_Kim | 0:c6fb5a9a8f91 | 31 | #endif |