I have a magnetic door switch, upon door open and close, my code was working perfectly alright...now that all of a sudden, I see that, when i open the door one time, i see lots of open, close, open close, open etcetra messages (kinda a unstable high and lows)
code here...
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;
import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;
public class GPIOTest {
public static void main(String[] args) throws InterruptedException {
System.out
.println("<--Pi4J--> AbstractGPIO Control Example ... started.");
// create gpio controller
final GpioController gpio = GpioFactory.getInstance();
try {
GpioPinDigitalInput gpioInput = gpio.provisionDigitalInputPin(
RaspiPin.GPIO_06, PinPullResistance.PULL_UP);
gpioInput.addListener(new GpioPinListenerDigital() {
@Override
public void handleGpioPinDigitalStateChangeEvent(
GpioPinDigitalStateChangeEvent event) {
// display pin state on console
System.out
.println(" --> DoorSensorInput PIN STATE CHANGE: "
+ event.getPin() + " = " + event.getState());
if (event.getState() == PinState.HIGH) {
System.out.println("Door -> opened");
} else {
System.out.println("Door -> closed");
}
}
});
Thread.sleep(15000);
} catch (Exception e) {
} finally {
// stop all AbstractGPIO activity/threads by shutting down the
// AbstractGPIO
// controller
// (this method will forcefully shutdown all AbstractGPIO monitoring
// threads
// and scheduled tasks)
gpio.shutdown();
System.out.println("Cleaned up...");
}
}
}
Please let me know why am i not getting one message like Opened or Closed....