import com.pi4j.io.gpio.GpioController; import com.pi4j.io.gpio.GpioFactory; import com.pi4j.io.gpio.GpioPinDigitalInput; import com.pi4j.io.gpio.GpioPinDigitalOutput; import com.pi4j.io.gpio.PinState; import com.pi4j.io.gpio.PinPullResistance; import com.pi4j.io.gpio.RaspiPin; import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent; import com.pi4j.io.gpio.event.GpioPinListenerDigital; public class ButtonLed { public static void main(String[] args) throws InterruptedException { final GpioController gpioCtrl = GpioFactory.getInstance(); final GpioPinDigitalInput button = gpioCtrl.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_UP); final GpioPinDigitalOutput pin = gpioCtrl.provisionDigitalOutputPin(RaspiPin.GPIO_01, "Red led", PinState.LOW); button.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF); pin.setShutdownOptions(true, PinState.LOW, PinPullResistance.OFF); button.addListener(new GpioPinListenerDigital() { @Override public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) { if (event.getState() == PinState.LOW) { System.out.println("Bouton enfoncé"); pin.high(); } else if (event.getState() == PinState.HIGH) { System.out.println("Bouton relaché"); pin.low(); } } }); while (true) { Thread.sleep(500); } //gpioCtrl.shutdown(); } }