public class LED extends DigitalOutputDevice
Provides utility methods for controlling a Light Emitting Diode (LED). Connect the cathode (short leg, flat side) of the LED to a ground pin; connect the anode (longer leg) to a limiting resistor; connect the other side of the limiting resistor to a GPIO pin (the limiting resistor can be placed either side of the LED). Example LED control, taken from LEDTest:
try (LED led = new LED(pin)) {
led.on();
SleepUtil.sleepSeconds(.5);
led.off();
SleepUtil.sleepSeconds(.5);
led.toggle();
SleepUtil.sleepSeconds(.5);
led.toggle();
SleepUtil.sleepSeconds(.5);
led.blink(0.5f, 0.5f, 10, false);
}
INFINITE_ITERATIONS
gpio
Constructor and Description |
---|
LED(GpioDeviceFactoryInterface deviceFactory,
int gpio) |
LED(GpioDeviceFactoryInterface deviceFactory,
int gpio,
boolean activeHigh,
boolean initialValue) |
LED(int gpio) |
LED(int gpio,
boolean activeHigh) |
Modifier and Type | Method and Description |
---|---|
void |
blink()
Blink indefinitely with 1 second on and 1 second off.
|
void |
blink(Action stopAction)
Blink indefinitely with 1 second on and 1 second off.
|
void |
blink(float onTime,
float offTime,
int n,
boolean background)
Blink.
|
void |
blink(float onTime,
float offTime,
int n,
boolean background,
Action stopAction)
Blink.
|
boolean |
isLit()
Return true if the LED is currently on.
|
close, isOn, off, on, onOffLoop, setOn, setValue, setValueUnsafe, toggle
getGpio
public LED(int gpio) throws RuntimeIOException
gpio
- GPIO to which the LED is connected.RuntimeIOException
- If an I/O error occurred.public LED(int gpio, boolean activeHigh) throws RuntimeIOException
gpio
- GPIO to which the LED is connected.activeHigh
- Set to true if a high output value represents on.RuntimeIOException
- If an I/O error occurred.public LED(GpioDeviceFactoryInterface deviceFactory, int gpio) throws RuntimeIOException
deviceFactory
- Device factory to use to construct the device.gpio
- GPIO to which the LED is connected.RuntimeIOException
- If an I/O error occurred.public LED(GpioDeviceFactoryInterface deviceFactory, int gpio, boolean activeHigh, boolean initialValue)
deviceFactory
- Device factory to use to construct the device.gpio
- GPIO to which the LED is connected.activeHigh
- Set to true if a high output value represents on.initialValue
- Initial value.RuntimeIOException
- If an I/O error occurred.public void blink() throws RuntimeIOException
RuntimeIOException
- If an I/O error occurred.public void blink(Action stopAction) throws RuntimeIOException
stopAction
- Action to invoke when the animation stops.RuntimeIOException
- If an I/O error occurred.public void blink(float onTime, float offTime, int n, boolean background) throws RuntimeIOException
onTime
- On time in seconds.offTime
- Off time in seconds.n
- 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.RuntimeIOException
- If an I/O error occurred.public void blink(float onTime, float offTime, int n, boolean background, Action stopAction) throws RuntimeIOException
onTime
- On time in seconds.offTime
- Off time in seconds.n
- 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.stopAction
- Action to invoke when the animation stops.RuntimeIOException
- If an I/O error occurred.public boolean isLit() throws RuntimeIOException
RuntimeIOException
- If an I/O error occurred.Copyright © 2016–2017 mattjlewis. All rights reserved.