Package com.diozero.devices
Class PwmLed
- java.lang.Object
-
- com.diozero.api.GpioDevice
-
- com.diozero.api.PwmOutputDevice
-
- com.diozero.devices.PwmLed
-
- All Implemented Interfaces:
DeviceInterface
,OutputDeviceInterface
,Closeable
,AutoCloseable
public class PwmLed extends PwmOutputDevice
PWM controlled LED. @see com.diozero.sampleapps.PwmLedTest PwmLedTest
-
-
Field Summary
-
Fields inherited from class com.diozero.api.PwmOutputDevice
INFINITE_ITERATIONS
-
Fields inherited from class com.diozero.api.GpioDevice
gpio
-
-
Constructor Summary
Constructors Constructor Description PwmLed(int gpio)
PwmLed(int gpio, float initialValue)
PwmLed(PwmOutputDeviceFactoryInterface deviceFactory, int gpio)
PwmLed(PwmOutputDeviceFactoryInterface deviceFactory, int gpio, float initialValue)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
blink()
Blink the LED on and off indefinitely.void
blink(float onTime, float offTime, int iterations, boolean background)
Blink the LED on and off repeatedly.boolean
isLit()
Return true if the PWM value is >0.void
pulse()
Pulse the LED on and off indefinitely in a background thread with a fade time of 1 second.void
pulse(float fadeTime, int steps, int iterations, boolean background)
Pulse the LED on and off repeatedly.-
Methods inherited from class com.diozero.api.PwmOutputDevice
close, fadeInOutLoop, getValue, isOn, off, on, onOffLoop, setValue, setValueInternal, toggle
-
Methods inherited from class com.diozero.api.GpioDevice
getGpio
-
-
-
-
Constructor Detail
-
PwmLed
public PwmLed(int gpio) throws RuntimeIOException
- Parameters:
gpio
- The GPIO to which the LED is attached to.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
PwmLed
public PwmLed(int gpio, float initialValue) throws RuntimeIOException
- Parameters:
gpio
- The GPIO to which the LED is attached to.initialValue
- Initial PWM output value (range 0..1).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
PwmLed
public PwmLed(PwmOutputDeviceFactoryInterface deviceFactory, int gpio) throws RuntimeIOException
- Parameters:
deviceFactory
- Device factory to use to provision this device.gpio
- The GPIO to which the LED is attached to.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
PwmLed
public PwmLed(PwmOutputDeviceFactoryInterface deviceFactory, int gpio, float initialValue) throws RuntimeIOException
- Parameters:
deviceFactory
- Device factory to use to provision this device.gpio
- The GPIO to which the LED is attached to.initialValue
- Initial PWM output value (range 0..1).- Throws:
RuntimeIOException
- If an I/O error occurred.
-
-
Method Detail
-
blink
public void blink() throws RuntimeIOException
Blink the LED on and off indefinitely.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
blink
public void blink(float onTime, float offTime, int iterations, boolean background) throws RuntimeIOException
Blink the LED on and off repeatedly.- Parameters:
onTime
- On time in seconds.offTime
- Off time in seconds.iterations
- Number of iterations. Set to <0 to blink indefinitely.background
- If true start a background thread to control the blink and return immediately. If false, only return once the blink iterations have finished.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
pulse
public void pulse() throws RuntimeIOException
Pulse the LED on and off indefinitely in a background thread with a fade time of 1 second.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
pulse
public void pulse(float fadeTime, int steps, int iterations, boolean background) throws RuntimeIOException
Pulse the LED on and off repeatedly.- Parameters:
fadeTime
- Time in seconds from fully on to fully off.steps
- Number of steps between fully on to fully off.iterations
- Number of times to fade in and out.background
- If true start a background thread to control the blink and return immediately. If false, only return once the blink iterations have finished.- Throws:
RuntimeIOException
- If an I/O error occurred.
-
isLit
public boolean isLit() throws RuntimeIOException
Return true if the PWM value is >0.- Returns:
- True if >0, false if 0.
- Throws:
RuntimeIOException
- If an I/O error occurred.
-
-