-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdafruit_PWMServoDriver.h
75 lines (63 loc) · 2.52 KB
/
Adafruit_PWMServoDriver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*!
* @file Adafruit_PWMServoDriver.h
*
* This is a library for our Adafruit 16-channel PWM & Servo driver.
*
* Designed specifically to work with the Adafruit 16-channel PWM & Servo driver.
*
* Pick one up today in the adafruit shop!
* ------> https://www.adafruit.com/product/815
*
* These driver use I2C to communicate, 2 pins are required to interface.
* For Arduino UNOs, thats SCL -> Analog 5, SDA -> Analog 4.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit andopen-source hardware by purchasing products
* from Adafruit!
*
* Limor Fried/Ladyada (Adafruit Industries).
*
* BSD license, all text above must be included in any redistribution
*/
/* This was updated by kiyoshigawa on 2019-09-28 to use the i2c_t3.h teensy wire library instead of the normal arduino Wire library */
#ifndef _ADAFRUIT_PWMServoDriver_H
#define _ADAFRUIT_PWMServoDriver_H
#include <Arduino.h>
#include <i2c_t3.h>
#define PCA9685_SUBADR1 0x2 /**< i2c bus address 1 */
#define PCA9685_SUBADR2 0x3 /**< i2c bus address 2 */
#define PCA9685_SUBADR3 0x4 /**< i2c bus address 3 */
#define PCA9685_MODE1 0x0 /**< Mode Register 1 */
#define PCA9685_MODE2 0x1 /**< Mode Register 2 */
#define PCA9685_PRESCALE 0xFE /**< Prescaler for PWM output frequency */
#define LED0_ON_L 0x6 /**< LED0 output and brightness control byte 0 */
#define LED0_ON_H 0x7 /**< LED0 output and brightness control byte 1 */
#define LED0_OFF_L 0x8 /**< LED0 output and brightness control byte 2 */
#define LED0_OFF_H 0x9 /**< LED0 output and brightness control byte 3 */
#define ALLLED_ON_L 0xFA /**< load all the LEDn_ON registers, byte 0 */
#define ALLLED_ON_H 0xFB /**< load all the LEDn_ON registers, byte 1 */
#define ALLLED_OFF_L 0xFC /**< load all the LEDn_OFF registers, byte 0 */
#define ALLLED_OFF_H 0xFD /**< load all the LEDn_OFF registers, byte 1 */
/*!
* @brief Class that stores state and functions for interacting with PCA9685 PWM chip
*/
class Adafruit_PWMServoDriver {
public:
Adafruit_PWMServoDriver(uint8_t addr = 0x40, i2c_t3 *I2C = &Wire);
void begin(uint8_t prescale = 0);
void reset();
void sleep();
void wakeup();
void setExtClk(uint8_t prescale);
void setPWMFreq(float freq);
void setOutputMode(bool totempole);
uint8_t getPWM(uint8_t num);
void setPWM(uint8_t num, uint16_t on, uint16_t off);
void setPin(uint8_t num, uint16_t val, bool invert=false);
private:
uint8_t _i2caddr;
i2c_t3 *_i2c;
uint8_t read8(uint8_t addr);
void write8(uint8_t addr, uint8_t d);
};
#endif