/** * Initialise GPIO to echo and trigger pins * * @param triggerGpioNum GPIO connected to the HC-SR04 trigger pin * @param echoGpioNum GPIO connected to the HC-SR04 echo pin * @throws RuntimeIOException if an I/O error occurs */ public HCSR04UsingEvents(int triggerGpioNum, int echoGpioNum) throws RuntimeIOException { lock = new ReentrantLock(); condition = lock.newCondition(); // Define device for trigger pin at HCSR04 trigger = new DigitalOutputDevice(triggerGpioNum, true, false); // Define device for echo pin at HCSR04 echo = new DigitalInputDevice(echoGpioNum, GpioPullUpDown.NONE, GpioEventTrigger.BOTH); echo.addListener(this); // Sleep for 20 ms - let the device settle? SleepUtil.sleepMillis(20); }
public TCS3200(int outGpio, int s2Gpio, int s3Gpio, int s0Gpio, int s1Gpio, int oeGpio) { out = new DigitalInputDevice(outGpio); s2 = new DigitalOutputDevice(s2Gpio); s3 = new DigitalOutputDevice(s3Gpio); if (s0Gpio != NOT_SET && s1Gpio != NOT_SET) { s0 = new DigitalOutputDevice(s0Gpio); s1 = new DigitalOutputDevice(s1Gpio); } if (oeGpio != NOT_SET) { // Enable device (active low) oe = new DigitalOutputDevice(oeGpio, false, true); } // Disable frequency output //out.setValue(false); setSampleSize(20); // One reading per second setUpdateInterval(1.0); // 2% setFrequency(Frequency.TWO_PERCENT); // Clear setFilter(Filter.CLEAR); out.addListener(this); Thread t = new Thread(this); t.start(); }
if (interrupt_gpio != null) { Logger.debug("Setting interruptGpio ({}) consumer", Integer.valueOf(interrupt_gpio.getGpio())); interrupt_gpio.addListener(this);