Closed rtt96 closed 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()); }
}`
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");
// 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() {
});
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());
}