All Downloads are FREE. Search and download functionalities are using the official Maven repository.

one.microproject.rpi.hardware.gpio.tests.HCSR501Test Maven / Gradle / Ivy

package one.microproject.rpi.hardware.gpio.tests;

import com.pi4j.io.gpio.event.GpioPinDigitalStateChangeEvent;
import com.pi4j.io.gpio.event.GpioPinListenerDigital;

import one.microproject.rpi.hardware.gpio.sensors.HCSR501;

public class HCSR501Test {

	public static void main(String[] args) throws InterruptedException {
		System.out.println("HC-SR501 PIR motion detection test started ...");
		
		HCSR501 hcsr501 = new HCSR501(12);
		
		GpioPinListenerDigital listener = new GpioPinListenerDigital() {

			@Override
			public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
				System.out.println("TrigerPin: " + event.getState().isHigh());
			}
			
		};
		
		hcsr501.start(listener);
		
		// keep program running until user aborts (CTRL-C)
		for (;;) {
			System.out.println("");
			Thread.sleep(2000);
		}
	}
		
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy