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