Package com.diozero.api
Class PwmOutputDevice
java.lang.Object
com.diozero.api.GpioDevice
com.diozero.api.PwmOutputDevice
- All Implemented Interfaces:
OutputDeviceInterface
,Closeable
,AutoCloseable
- Direct Known Subclasses:
PwmLed
public class PwmOutputDevice extends GpioDevice implements OutputDeviceInterface
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
gpio
-
Constructor Summary
Constructors Constructor Description PwmOutputDevice(int gpio)
PwmOutputDevice(int gpio, float initialValue)
PwmOutputDevice(int gpio, int pwmFrequency, float initialValue)
PwmOutputDevice(PwmOutputDeviceFactoryInterface pwmDeviceFactory, int gpio, float initialValue)
PwmOutputDevice(PwmOutputDeviceFactoryInterface pwmDeviceFactory, int gpio, int pwmFrequency, float initialValue)
-
Method Summary
Modifier and Type Method Description void
close()
protected void
fadeInOutLoop(float fadeTime, int steps, int iterations, boolean background)
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
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 Details
-
INFINITE_ITERATIONS
public static final int INFINITE_ITERATIONS- See Also:
- Constant Field Values
-
-
Constructor Details
-
PwmOutputDevice
- Parameters:
gpio
- GPIO to which the output device is connected.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
PwmOutputDevice
- 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
- 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 pwmDeviceFactory, int gpio, float initialValue) throws RuntimeIOException- Parameters:
pwmDeviceFactory
- 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 pwmDeviceFactory, int gpio, int pwmFrequency, float initialValue) throws RuntimeIOException- Parameters:
pwmDeviceFactory
- Device factory to use to provision this device.gpio
- 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 Details
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
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
- Throws:
RuntimeIOException
-
getValue
Get the current PWM output value (0..1).- Returns:
- Current PWM output value.
- Throws:
RuntimeIOException
- If an I/O error occurred.
-
setValue
Set the PWM output value (0..1).- Specified by:
setValue
in interfaceOutputDeviceInterface
- Parameters:
value
- New PWM output value.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
on
Turn on the device (same assetValue(1)
).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
off
Turn off the device (same assetValue(0)
).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
toggle
Toggle the state of the device (same assetValue(1 - getvalue())
).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
isOn
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.
-