Pi4jInterrupt/src/pi4jinterrupt/Pi4jInterrupt.java
/**
     * @param args the command line arguments
     */
@param args the command line arguments
@param args the command line arguments
public static void main(String args[]) throws InterruptedException {
        System.out.println("<--Pi4J--> GPIO Listen Example ... started.");
        final GpioController gpio = GpioFactory.getInstance();
        final GpioPinDigitalInput myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_00, PinPullResistance.PULL_DOWN);
        myButton.setShutdownOptions(true);
        myButton.addListener(new GpioPinListenerDigital() {
            @Override
            public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                System.out.println(" --> GPIO PIN STATE CHANGE: " + event.getPin() + " = " + event.getState());
            } 
        });
        System.out.println(" ... complete the GPIO #02 circuit and see the listener feedback here in the console.");
        while(true) {
            Thread.sleep(500);
        }
    }
public static void main ( String args [ ] ) throws InterruptedException { System . out . println ( "<--Pi4J--> GPIO Listen Example ... started." ) ; final GpioController gpio = GpioFactory . getInstance ( ) ; final GpioPinDigitalInput myButton = gpio . provisionDigitalInputPin ( RaspiPin . GPIO_00 , PinPullResistance . PULL_DOWN ) ; myButton . setShutdownOptions ( true ) ; myButton . addListener ( new GpioPinListenerDigital ( ) { @ Override public void handleGpioPinDigitalStateChangeEvent ( GpioPinDigitalStateChangeEvent event ) { System . out . println ( " --> GPIO PIN STATE CHANGE: " + event . getPin ( ) + " = " + event . getState ( ) ) ; } } ) ; System . out . println ( " ... complete the GPIO #02 circuit and see the listener feedback here in the console." ) ; while ( true ) { Thread . sleep ( 500 ) ; } }
@param args the command line arguments
@param args the command line arguments
// create gpio controller // provision gpio pin #02 as an input pin with its internal pull down resistor enabled // set shutdown state for this input pin // create and register gpio pin listener // display pin state on console // keep program running until user aborts (CTRL-C) // stop all GPIO activity/threads by shutting down the GPIO controller // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks) // gpio.shutdown();   <--- implement this method call if you wish to terminate the Pi4J GPIO controller