public class PCA9685 extends I2CComponent
Datasheet: PCA9685
Each channel has 4 registers of 8 bits:
The implementation of this component is mainly based on:
Modifier and Type | Class and Description |
---|---|
static class |
PCA9685.PCA9685Channel
16 channels are available on the PCA9685 module,
numbered from 0 to 15.
|
Modifier and Type | Field and Description |
---|---|
static int |
AI
[datasheet - p.14] Mode register 1, MODE1.
|
static int |
ALL_LED_OFF_H
[datasheet - p.13] Register address.
|
static int |
ALL_LED_OFF_L
[datasheet - p.13] Register address.
|
static int |
ALL_LED_ON_H
[datasheet - p.13] Register address.
|
static int |
ALL_LED_ON_L
[datasheet - p.13] Register address.
|
static int |
ALLCALL
[datasheet - p.14] Mode register 1, MODE1.
|
static int |
ALLCALLADR
[datasheet - p.10] Register address.
|
static int |
DEFAULT_I2C_ADDRESS
Defautl i2c address for the PCA9685 component.
|
static int |
EXTCLK
[datasheet - p.14] Mode register 1, MODE1.
|
static int |
INVRT
[datasheet - p.16] Mode register 2, MODE2.
|
static int |
LED0_OFF_H
[datasheet - p.10] Register address.
|
static int |
LED0_OFF_L
[datasheet - p.10] Register address.
|
static int |
LED0_ON_H
[datasheet - p.10] Register address.
|
static int |
LED0_ON_L
[datasheet - p.10] Register address.
|
static int |
MAX_FREQUENCY
Maximum frequency for the PWM signals generated by the PCA9685, in Hz.
|
static int |
MIN_FREQUENCY
Minimum frequency for the PWM signals generated by the PCA9685, in Hz.
|
static int |
MODE1
[datasheet - p.10] Register address.
|
static int |
MODE2
[datasheet - p.10] Register address.
|
static int |
OCH
[datasheet - p.16] Mode register 2, MODE2.
|
static int |
OUTDRV
[datasheet - p.16] Mode register 2, MODE2.
|
static int |
OUTNE
[datasheet - p.16] Mode register 2, MODE2.
|
static int |
PRE_SCALE
[datasheet - p.13] Register address.
|
static int |
REGISTERS_PER_LED
[datasheet - p.10] Register address.
|
static int |
RESTART
[datasheet - p.14] Mode register 1, MODE1.
|
static int |
SLEEP
[datasheet - p.14] Mode register 1, MODE1.
|
static int |
SUB1
[datasheet - p.14] Mode register 1, MODE1.
|
static int |
SUB2
[datasheet - p.14] Mode register 1, MODE1.
|
static int |
SUB3
[datasheet - p.14] Mode register 1, MODE1.
|
static int |
SUBADR1
[datasheet - p.10] Register address.
|
static int |
SUBADR2
[datasheet - p.10] Register address.
|
static int |
SUBADR3
[datasheet - p.10] Register address.
|
device, MAX_I2C_ADDRESS, MIN_I2C_ADDRESS
Constructor and Description |
---|
PCA9685()
Default constructor for a PCA9685 using the default i2c address of the component.
|
PCA9685(int i2cAddress)
Constructor for a PCA9685 using a specific i2c address.
|
Modifier and Type | Method and Description |
---|---|
void |
setAllPWM(int on,
int off)
Sets the start and end of the high segment of the PWM pulse, for all the PWM channels of the PCA9685.
|
void |
setPWM(PCA9685.PCA9685Channel channel,
int on,
int off)
Sets the start (on) and end (off) of the high segment of the PWM pulse, on a specific channel.
|
void |
setPWMFreq(int frequency)
Sets the PWM frequency, which determines how many full pulses per second are generated by the module.
|
getDevice, getType, readSignedRegisterValue, readTwoSignedRegsiters, readTwoUnsignedRegisters, readUnsignedRegisterValue, writeUnsignedValueDirectlyToI2CDevice, writeUnsignedValueToRegister
public static final int DEFAULT_I2C_ADDRESS
public static final int MODE1
Mode register 1.
public static final int MODE2
Mode register 2.
public static final int SUBADR1
i2c-bus subaddress 1.
public static final int SUBADR2
i2c-bus subaddress 2.
public static final int SUBADR3
i2c-bus subaddress 3.
public static final int ALLCALLADR
LED All Call i2c-bus address.
public static final int LED0_ON_L
LED0 output and brightness control byte 0.
Equivalent for other LEDs can be accessed with: (for LED number LED_NB)
LED0_ON_L + LED_NB * REGISTERS_PER_LED
public static final int LED0_ON_H
LED0 output and brightness control byte 0.
Equivalent for other LEDs can be accessed with: (for LED number LED_NB)
LED0_ON_H + LED_NB * REGISTERS_PER_LED
public static final int LED0_OFF_L
LED0 output and brightness control byte 0.
Equivalent for other LEDs can be accessed with: (for LED number LED_NB)
LED0_OFF_L + LED_NB * REGISTERS_PER_LED
public static final int LED0_OFF_H
LED0 output and brightness control byte 0.
Equivalent for other LEDs can be accessed with: (for LED number LED_NB)
LED0_OFF_H + LED_NB * REGISTERS_PER_LED
public static final int REGISTERS_PER_LED
Number of registers used for each of the 16 LEDs.
public static final int ALL_LED_ON_L
Load all the LEDn_ON registers, byte 0.
public static final int ALL_LED_ON_H
Load all the LEDn_ON registers, byte 1.
public static final int ALL_LED_OFF_L
Load all the LEDn_OFF registers, byte 0.
public static final int ALL_LED_OFF_H
Load all the LEDn_OFF registers, byte 1.
public static final int PRE_SCALE
Prescaled for PWM output frequency.
The PRE_SCALE register defines the frequency at which the outputs modulate. The prescale value is determined with the formula shown in Equation 1, p.25 in datasheet.
prescale_value = round(osc_clock/(4096*update_rate) -1
public static final int RESTART
Restart enabled.
public static final int EXTCLK
Use EXTCLK pin clock.
public static final int AI
Register Auto-Increment enabled.
public static final int SLEEP
Low power mode. Oscillator off.
public static final int SUB1
PCA9685 responds to I2C-bus subaddress 1.
public static final int SUB2
PCA9685 responds to I2C-bus subaddress 2.
public static final int SUB3
PCA9685 responds to I2C-bus subaddress 3.
public static final int ALLCALL
PCA9685 responds to LED All Call I2C-bus address.
public static final int INVRT
Output logic state inverted. Value to use when no external driver used. Applicable when OE = 0.
public static final int OCH
Outputs change on ACK.
public static final int OUTDRV
The 16 LEDn outputs are configured with a totem pole structure.
public static final int OUTNE
When OE = 1 (output drivers not enabled):
public static final int MAX_FREQUENCY
public static final int MIN_FREQUENCY
public PCA9685()
public PCA9685(int i2cAddress)
i2cAddress
- the i2c address of the PCA9685.public void setPWMFreq(int frequency)
frequency
- the frequency in Hz, in the MAX_FREQUENCY
..MIN_FREQUENCY
range.public void setPWM(PCA9685.PCA9685Channel channel, int on, int off)
channel
- the channel that should be updated with the new values.on
- the tick, between 0 and 4096, when the signal should transition from low to high.off
- the tick, between on and 4096, when the signal should transition from high to low.setAllPWM(int, int)
public void setAllPWM(int on, int off)
on
- the tick, between 0 and 4096, when the signal should transition from low to high.off
- the tick, between on and 4096, when the signal should transition from high to low.setPWM(PCA9685Channel, int, int)