public class Button extends GPIOComponent
This component only uses one Gpio pin.
As an example, you can use this kind of component: Momentary Pushbutton Switch
Example of use: JoystickExample
Modifier and Type | Field and Description |
---|---|
protected com.pi4j.io.gpio.GpioPinDigitalInput |
digitalInput |
gpio
Constructor and Description |
---|
Button(GPIOPin pin)
Constructor for a new button, using a specific Gpio pin.
|
Button(GPIOPin pin,
boolean highIsPressed)
Constructor for a new button, using a specific Gpio pin,
and specifying the signal corresponding to the button pressed state: high or low.
|
Modifier and Type | Method and Description |
---|---|
com.pi4j.io.gpio.GpioPinDigitalInput |
getGpioPinDigitalInput()
Get the pi4j GpioPinDigitalInput corresponding to this button.
|
boolean |
isPressed()
Checks if the button is currently pressed.
|
getType
public Button(GPIOPin pin)
pin
- the pin used to deal with the button.public Button(GPIOPin pin, boolean highIsPressed)
pin
- the Gpio pin used to deal with the button.highIsPressed
- true if a high signal corresponds to button pressed. false otherwise.public boolean isPressed()
public com.pi4j.io.gpio.GpioPinDigitalInput getGpioPinDigitalInput()
This can be usefull to add custom listeners to easily react when the button is pressed/released.