Package com.diozero.devices
Class PCA9685
- java.lang.Object
-
- com.diozero.internal.spi.AbstractDeviceFactory
-
- com.diozero.devices.PCA9685
-
- All Implemented Interfaces:
DeviceInterface
,DeviceFactoryInterface
,PwmOutputDeviceFactoryInterface
,ServoDeviceFactoryInterface
,AutoCloseable
public class PCA9685 extends AbstractDeviceFactory implements PwmOutputDeviceFactoryInterface, ServoDeviceFactoryInterface, DeviceInterface
PCA9685 I2C-bus controlled 16-channel 12-bit PWM controller as used in the popular Adafruit PWM add-on board Datasheet: http://www.nxp.com/documents/data_sheet/PCA9685.pdf
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PCA9685.PCA9685BoardPinInfo
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_ADDRESS
-
Fields inherited from class com.diozero.internal.spi.AbstractDeviceFactory
closed, deviceStates
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this device factory including all devices that have been provisioned by it.void
closeChannel(int channel)
InternalPwmOutputDeviceInterface
createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue)
InternalServoDeviceInterface
createServoDevice(String key, PinInfo pinInfo, int frequency, int minPulseWidthUs, int maxPulseWidthUs, int initialPulseWidthUs)
BoardPinInfo
getBoardPinInfo()
Get information about pins that can be provisioned by this device factory.int
getBoardPwmFrequency()
int
getBoardServoFrequency()
int
getDutyUs(int channel)
String
getName()
Get the name of this device factoryfloat
getValue(int channel)
Get the PWM output percentage for the specified channel, range 0..1void
setBoardPwmFrequency(int pwmFrequency)
void
setBoardServoFrequency(int pwmFrequency)
void
setDutyUs(int channel, int dutyUs)
Set PWM duty cycle output in microseconds for the specified channel.void
setValue(int channel, float value)
Set PWM output percentage for the specified channel, value must be 0..1-
Methods inherited from class com.diozero.internal.spi.AbstractDeviceFactory
createI2CKey, createPinKey, createPwmPinKey, createSerialKey, createServoPinKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, reopen
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.diozero.internal.spi.DeviceFactoryInterface
createI2CKey, createPinKey, createPwmPinKey, createSerialKey, createServoPinKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, reopen, start
-
Methods inherited from interface com.diozero.internal.spi.PwmOutputDeviceFactoryInterface
provisionPwmOutputDevice
-
Methods inherited from interface com.diozero.internal.spi.ServoDeviceFactoryInterface
provisionServoDevice
-
-
-
-
Field Detail
-
DEFAULT_ADDRESS
public static final int DEFAULT_ADDRESS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PCA9685
public PCA9685(int pwmFrequency) throws RuntimeIOException
- Throws:
RuntimeIOException
-
PCA9685
public PCA9685(int controller, int pwmFrequency) throws RuntimeIOException
- Throws:
RuntimeIOException
-
PCA9685
public PCA9685(int controller, int address, int pwmFrequency) throws RuntimeIOException
- Throws:
RuntimeIOException
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:DeviceFactoryInterface
Get the name of this device factory- Specified by:
getName
in interfaceDeviceFactoryInterface
- Returns:
- the name of this device factory
-
close
public void close() throws RuntimeIOException
Description copied from interface:DeviceFactoryInterface
Close this device factory including all devices that have been provisioned by it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDeviceFactoryInterface
- Specified by:
close
in interfaceDeviceInterface
- Overrides:
close
in classAbstractDeviceFactory
- Throws:
RuntimeIOException
-
closeChannel
public void closeChannel(int channel) throws RuntimeIOException
- Throws:
RuntimeIOException
-
createPwmOutputDevice
public InternalPwmOutputDeviceInterface createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue) throws RuntimeIOException
- Specified by:
createPwmOutputDevice
in interfacePwmOutputDeviceFactoryInterface
- Throws:
RuntimeIOException
-
createServoDevice
public InternalServoDeviceInterface createServoDevice(String key, PinInfo pinInfo, int frequency, int minPulseWidthUs, int maxPulseWidthUs, int initialPulseWidthUs) throws RuntimeIOException
- Specified by:
createServoDevice
in interfaceServoDeviceFactoryInterface
- Throws:
RuntimeIOException
-
getValue
public float getValue(int channel) throws RuntimeIOException
Get the PWM output percentage for the specified channel, range 0..1- Parameters:
channel
- PWM channel- Returns:
- output PWM "on" percentage, range 0..1
- Throws:
RuntimeIOException
- if an I/O error occurs
-
setValue
public void setValue(int channel, float value) throws RuntimeIOException
Set PWM output percentage for the specified channel, value must be 0..1- Parameters:
channel
- PWM channelvalue
- Must be 0..1- Throws:
RuntimeIOException
- if an I/O error occurs
-
getDutyUs
public int getDutyUs(int channel)
-
setDutyUs
public void setDutyUs(int channel, int dutyUs) throws RuntimeIOException
Set PWM duty cycle output in microseconds for the specified channel. A standard servo has a minimum range of 1-2 milliseconds. The actual range varies between devices. E.g. My TowerPro SG90 has a pulse width range of 500-2,400 us.- Parameters:
channel
- PWM channeldutyUs
- New duty value in microseconds- Throws:
RuntimeIOException
- if an I/O error occurs
-
getBoardPwmFrequency
public int getBoardPwmFrequency()
- Specified by:
getBoardPwmFrequency
in interfacePwmOutputDeviceFactoryInterface
-
setBoardPwmFrequency
public void setBoardPwmFrequency(int pwmFrequency)
- Specified by:
setBoardPwmFrequency
in interfacePwmOutputDeviceFactoryInterface
-
getBoardServoFrequency
public int getBoardServoFrequency()
- Specified by:
getBoardServoFrequency
in interfaceServoDeviceFactoryInterface
-
setBoardServoFrequency
public void setBoardServoFrequency(int pwmFrequency)
- Specified by:
setBoardServoFrequency
in interfaceServoDeviceFactoryInterface
-
getBoardPinInfo
public BoardPinInfo getBoardPinInfo()
Description copied from interface:DeviceFactoryInterface
Get information about pins that can be provisioned by this device factory.- Specified by:
getBoardPinInfo
in interfaceDeviceFactoryInterface
- Returns:
- board pin info instance for this device factory
-
-