Pi4J / pi4j-v1

DEPRECATED Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART)
http://www.pi4j.com
Apache License 2.0
1.31k stars 448 forks source link

GpioPinListenerDigital listener does not work(faills to fire) #505

Closed rtt96 closed 3 years ago

rtt96 commented 3 years ago

I have an RPi4b fully upgraded, has wiringpi version2.52 but the GpioPinListenerDigital change listener does not work. I am using this with PIR motion sensor but somehow the listener does not work. Please help, I am using the following code.

`public static void main(String[] args) { System.out.println("begin");

      ///GpioFactory.setDefaultProvider(new RaspiGpioProvider(RaspiPinNumberingScheme.BROADCOM_PIN_NUMBERING));

// create gpio controller
final GpioController gpioSensor = GpioFactory.getInstance(); final GpioPinDigitalInput sensor = gpioSensor.provisionDigitalInputPin(RaspiPin.GPIO_04, PinPullResistance.PULL_DOWN);

// create another gpio controller

// create and register gpio pin listener
sensor.addListener(new GpioPinListenerDigital() {

@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {        

    if(event.getState().isHigh()){  
        System.out.println("Intruder Alert!"); 
    }   

    if(event.getState().isLow()){   
        System.out.println("Secured");
    }   

}       

});

System.out.println("Alt..."); try {
// keep program running until user aborts
for (;;) {
System.out.println("working"); Thread.sleep(500);
}
}
catch (final Exception e) {
System.out.println(e.getMessage());
}

 }`