在这个程序中,我可以读取GPIO引脚。但是按下硬件按钮(GPIO连接的按钮)会导致单个事件引起状态爆发性变化,并导致一系列动作事件的爆发。那么,我如何消除同时发生的GPIO状态变化,以消除这个爆发。
final GpioController gpio = GpioFactory.getInstance();
GpioPinDigitalInput myButton = null;
try {
myButton = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02,PinPullResistance.PULL_DOWN);
} catch(GpioPinExistsException e) {
}
try {
myButton.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
if(event.getState().toString().equalsIgnoreCase("HIGH") || event.getState().toString().equalsIgnoreCase("LOW")) {
System.out.println("Pressed");
}
}
});
} catch(NullPointerException e2) {
}