Package com.diozero.api
Class PwmOutputDevice
- java.lang.Object
-
- com.diozero.api.GpioDevice
-
- com.diozero.api.PwmOutputDevice
-
- All Implemented Interfaces:
DeviceInterface
,AutoCloseable
- Direct Known Subclasses:
PwmLed
public class PwmOutputDevice extends GpioDevice
Provide generic Pulse Width Modulation (PWM) output control.
-
-
Field Summary
Fields Modifier and Type Field Description static int
INFINITE_ITERATIONS
-
Fields inherited from class com.diozero.api.GpioDevice
pinInfo
-
-
Constructor Summary
Constructors Constructor Description PwmOutputDevice(int gpio)
PwmOutputDevice(int gpio, float initialValue)
PwmOutputDevice(int gpio, int pwmFrequency, float initialValue)
PwmOutputDevice(PwmOutputDeviceFactoryInterface deviceFactory, int gpio, float initialValue)
PwmOutputDevice(PwmOutputDeviceFactoryInterface deviceFactory, int pwmOrGpioNum, int pwmFrequency, float initialValue)
PwmOutputDevice(PwmOutputDeviceFactoryInterface deviceFactory, PinInfo pinInfo, int pwmFrequency, float initialValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this deviceprotected void
fadeInOutLoop(float fadeTime, int steps, int iterations, boolean background)
int
getPwmFrequency()
float
getValue()
Get the current PWM output value (0..1).boolean
isOn()
Get the device on / off status.void
off()
Turn off the device (same assetValue(0)
).void
on()
Turn on the device (same assetValue(1)
).protected void
onOffLoop(float onTime, float offTime, int n, boolean background)
void
setPwmFrequency(int pwmFrequency)
void
setValue(float value)
Set the PWM output value (0..1).protected void
setValueInternal(float value)
void
toggle()
Toggle the state of the device (same assetValue(1 - getvalue())
).-
Methods inherited from class com.diozero.api.GpioDevice
getGpio
-
-
-
-
Field Detail
-
INFINITE_ITERATIONS
public static final int INFINITE_ITERATIONS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PwmOutputDevice
public PwmOutputDevice(int gpio) throws RuntimeIOException
- Parameters:
gpio
- GPIO to which the output device is connected.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
PwmOutputDevice
public PwmOutputDevice(int gpio, float initialValue) throws RuntimeIOException
- Parameters:
gpio
- GPIO to which the output device is connected.initialValue
- Initial output value (0..1).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
PwmOutputDevice
public PwmOutputDevice(int gpio, int pwmFrequency, float initialValue) throws RuntimeIOException
- Parameters:
gpio
- GPIO to which the output device is connected.initialValue
- Initial output value (0..1).pwmFrequency
- PWM frequency (Hz).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
PwmOutputDevice
public PwmOutputDevice(PwmOutputDeviceFactoryInterface deviceFactory, int gpio, float initialValue) throws RuntimeIOException
- Parameters:
deviceFactory
- Device factory to use to provision this device.gpio
- GPIO to which the output device is connected.initialValue
- Initial output value (0..1).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
PwmOutputDevice
public PwmOutputDevice(PwmOutputDeviceFactoryInterface deviceFactory, int pwmOrGpioNum, int pwmFrequency, float initialValue) throws RuntimeIOException
- Parameters:
deviceFactory
- Device factory to use to provision this device.pwmOrGpioNum
- GPIO to which the output device is connected.pwmFrequency
- PWM frequency (Hz).initialValue
- Initial output value (0..1).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
PwmOutputDevice
public PwmOutputDevice(PwmOutputDeviceFactoryInterface deviceFactory, PinInfo pinInfo, int pwmFrequency, float initialValue) throws RuntimeIOException
- Parameters:
deviceFactory
- Device factory to use to provision this device.pinInfo
- GPIO to which the output device is connected.pwmFrequency
- PWM frequency (Hz).initialValue
- Initial output value (0..1).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
-
Method Detail
-
close
public void close()
Description copied from interface:DeviceInterface
Close this device
-
onOffLoop
protected void onOffLoop(float onTime, float offTime, int n, boolean background) throws RuntimeIOException
- Throws:
RuntimeIOException
-
fadeInOutLoop
protected void fadeInOutLoop(float fadeTime, int steps, int iterations, boolean background) throws RuntimeIOException
- Throws:
RuntimeIOException
-
setValueInternal
protected void setValueInternal(float value) throws RuntimeIOException
- Throws:
RuntimeIOException
-
getValue
public float getValue() throws RuntimeIOException
Get the current PWM output value (0..1).- Returns:
- Current PWM output value.
- Throws:
RuntimeIOException
- If an I/O error occurred.
-
setValue
public void setValue(float value) throws RuntimeIOException
Set the PWM output value (0..1).- Parameters:
value
- New PWM output value.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
getPwmFrequency
public int getPwmFrequency()
-
setPwmFrequency
public void setPwmFrequency(int pwmFrequency) throws RuntimeIOException
- Throws:
RuntimeIOException
-
on
public void on() throws RuntimeIOException
Turn on the device (same assetValue(1)
).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
off
public void off() throws RuntimeIOException
Turn off the device (same assetValue(0)
).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
toggle
public void toggle() throws RuntimeIOException
Toggle the state of the device (same assetValue(1 - getvalue())
).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
isOn
public boolean isOn() throws RuntimeIOException
Get the device on / off status.- Returns:
- Returns true if the device currently has a value > 0.
- Throws:
RuntimeIOException
- If an I/O error occurred.
-
-