2021.12.22
Dependents: 4dof_attitude 4dof_screw
PCA9685.h@3:a4e0f41bd0b6, 2022-02-24 (annotated)
- Committer:
- Kotttaro
- Date:
- Thu Feb 24 06:13:32 2022 +0000
- Revision:
- 3:a4e0f41bd0b6
- Parent:
- 0:a95a8df36651
2022.02.24
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kotttaro | 0:a95a8df36651 | 1 | #ifndef _PCA9685_H |
Kotttaro | 0:a95a8df36651 | 2 | #define _PCA9685_H |
Kotttaro | 0:a95a8df36651 | 3 | |
Kotttaro | 0:a95a8df36651 | 4 | //#if ARDUINO >= 100 |
Kotttaro | 0:a95a8df36651 | 5 | // #include "Arduino.h" |
Kotttaro | 0:a95a8df36651 | 6 | //#else |
Kotttaro | 0:a95a8df36651 | 7 | // #include "WProgram.h" |
Kotttaro | 0:a95a8df36651 | 8 | //#endif |
Kotttaro | 0:a95a8df36651 | 9 | |
Kotttaro | 0:a95a8df36651 | 10 | #include"mbed.h" |
Kotttaro | 0:a95a8df36651 | 11 | |
Kotttaro | 0:a95a8df36651 | 12 | #define PCA9685_SUBADR1 0x2 |
Kotttaro | 0:a95a8df36651 | 13 | #define PCA9685_SUBADR2 0x3 |
Kotttaro | 0:a95a8df36651 | 14 | #define PCA9685_SUBADR3 0x4 |
Kotttaro | 0:a95a8df36651 | 15 | |
Kotttaro | 0:a95a8df36651 | 16 | #define PCA9685_MODE1 0x0 |
Kotttaro | 0:a95a8df36651 | 17 | #define PCA9685_PRESCALE 0xFE |
Kotttaro | 0:a95a8df36651 | 18 | |
Kotttaro | 0:a95a8df36651 | 19 | #define LED0_ON_L 0x6 |
Kotttaro | 0:a95a8df36651 | 20 | #define LED0_ON_H 0x7 |
Kotttaro | 0:a95a8df36651 | 21 | #define LED0_OFF_L 0x8 |
Kotttaro | 0:a95a8df36651 | 22 | #define LED0_OFF_H 0x9 |
Kotttaro | 0:a95a8df36651 | 23 | |
Kotttaro | 0:a95a8df36651 | 24 | #define ALLLED_ON_L 0xFA |
Kotttaro | 0:a95a8df36651 | 25 | #define ALLLED_ON_H 0xFB |
Kotttaro | 0:a95a8df36651 | 26 | #define ALLLED_OFF_L 0xFC |
Kotttaro | 0:a95a8df36651 | 27 | #define ALLLED_OFF_H 0xFD |
Kotttaro | 0:a95a8df36651 | 28 | |
Kotttaro | 0:a95a8df36651 | 29 | |
Kotttaro | 0:a95a8df36651 | 30 | class PCA9685 { |
Kotttaro | 0:a95a8df36651 | 31 | public: |
Kotttaro | 0:a95a8df36651 | 32 | //PCA9685(uint8_t addr = 0x40); |
Kotttaro | 0:a95a8df36651 | 33 | void begin(void); |
Kotttaro | 0:a95a8df36651 | 34 | void reset(void); |
Kotttaro | 0:a95a8df36651 | 35 | void setPWMFreq(float freq); |
Kotttaro | 0:a95a8df36651 | 36 | void setPWM(uint8_t num, uint16_t on, uint16_t off); |
Kotttaro | 0:a95a8df36651 | 37 | void setPin(uint8_t num, uint16_t val, bool invert=false); |
Kotttaro | 0:a95a8df36651 | 38 | |
Kotttaro | 0:a95a8df36651 | 39 | private: |
Kotttaro | 0:a95a8df36651 | 40 | uint8_t i2c_addr; |
Kotttaro | 0:a95a8df36651 | 41 | |
Kotttaro | 0:a95a8df36651 | 42 | uint8_t read8(uint8_t addr); |
Kotttaro | 0:a95a8df36651 | 43 | void write8(uint8_t addr, uint8_t d); |
Kotttaro | 0:a95a8df36651 | 44 | }; |
Kotttaro | 0:a95a8df36651 | 45 | |
Kotttaro | 0:a95a8df36651 | 46 | #endif |