Package com.diozero.devices
Class PCA9685
- java.lang.Object
-
- com.diozero.internal.spi.AbstractDeviceFactory
-
- com.diozero.devices.PCA9685
-
- All Implemented Interfaces:
DeviceInterface
,DeviceFactoryInterface
,PwmOutputDeviceFactoryInterface
,AutoCloseable
public class PCA9685 extends AbstractDeviceFactory implements PwmOutputDeviceFactoryInterface, 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)
PwmOutputDeviceInterface
createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue)
BoardPinInfo
getBoardPinInfo()
Get information about pins that can be provisioned by this device factory.int
getBoardPwmFrequency()
String
getName()
Get the name of this device factoryfloat
getValue(int channel)
void
setBoardPwmFrequency(int pwmFrequency)
void
setServoPulseWidthMs(int channel, double pulseWidthMs)
Set the pulse duration (micro-seconds) E.g.void
setValue(int channel, float value)
Set PWM output on a specific channel, value must be 0..1-
Methods inherited from class com.diozero.internal.spi.AbstractDeviceFactory
createI2CKey, createPinKey, createSerialKey, 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, createSerialKey, createSpiKey, deviceClosed, deviceOpened, getDevice, isClosed, isDeviceOpened, reopen, start
-
Methods inherited from interface com.diozero.internal.spi.PwmOutputDeviceFactoryInterface
provisionPwmOutputDevice
-
-
-
-
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
-
setServoPulseWidthMs
public void setServoPulseWidthMs(int channel, double pulseWidthMs) throws RuntimeIOException
Set the pulse duration (micro-seconds) E.g. For TowerPro SG90 servo pulse width range = 500-2400 us TowerPro SG5010 servo pulse width range = 1ms-2ms- Parameters:
channel
- PWM channelpulseWidthMs
- The desired pulse width in milli-seconds- Throws:
RuntimeIOException
- if an I/O error occurs
-
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 PwmOutputDeviceInterface createPwmOutputDevice(String key, PinInfo pinInfo, int pwmFrequency, float initialValue) throws RuntimeIOException
- Specified by:
createPwmOutputDevice
in interfacePwmOutputDeviceFactoryInterface
- Throws:
RuntimeIOException
-
getValue
public float getValue(int channel) throws RuntimeIOException
- Throws:
RuntimeIOException
-
setValue
public void setValue(int channel, float value) throws RuntimeIOException
Set PWM output on a specific channel, value must be 0..1- Parameters:
channel
- PWM channelvalue
- Must be 0..1- 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
-
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
-
-