/** * default constructor; using this constructor assumes that: * (1) a pin state of HIGH is BUTTON PRESSED * (2) a pin state of LOW is BUTTON RELEASED * * @param pin GPIO digital input pin */ public GpioButtonComponent(GpioPinDigitalInput pin) { this.pin = pin; // add pin listener this.pin.addListener(pinListener); }
/** * Return 'true' if motion is currently detected * based on the GPIO digital input pin state. * * @return motion detected status */ @Override public boolean isMotionDetected() { return pin.isState(motionDetectedState); } }
@Override public void setDebounceTimeMillis(int debounceTime) { digitalInputPin.setDebounce(debounceTime); }
@Override public void enableListener() { digitalInputPin.removeAllListeners(); digitalInputPin.addListener(this); }
PinState myButtonState = myButton.getState(); boolean buttonPressed = myButton.isHigh(); myButton.addListener(new GpioUsageExampleListener()); myButton.addTrigger(new GpioSyncStateTrigger(myLed));
myButton.setShutdownOptions(true); myButton.addListener(new GpioPinListenerDigital() { @Override public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
try { GpioPinDigitalInput provisionedPin = gpio.provisionDigitalInputPin(pin, pull); provisionedPin.setShutdownOptions(true); // unexport pin on program shutdown input.getState().isHigh(), // conditional expression input.getState()));
@Override public void run() { // if the current pin state is not the same as the original pin state, // then we need to raise a new pin event to notify the user that the pin // state has changed during the debounce delay period if(!pin.isState(originalPinState)){ // add a new pin event notification to the thread pool for *immediate* execution executor.execute(new GpioEventDispatchTaskImpl(pin, new PinDigitalStateChangeEvent(this, pin.getPin(), pin.getState()))); } } }
pin.setProperty("last_known_state", pin.getState().name()); if(!pin.getState().name().equals(pin.getProperty("last_known_state"))){ pin.getState().isHigh(), // conditional expression pin.getState())); // text to display pin.setProperty("last_known_state", pin.getState().name());
myButton.setDebounce(1000); myButton.addListener(new GpioPinListenerDigital() { @Override public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
myButton.setShutdownOptions(true); console.println(" ... Successfully provisioned [" + myButton.getPin() + "] with PULL resistance = [" + myButton.getPin() + "]"); console.emptyLine(); console.box("Please complete the [" + myButton.getPin() + "] circuit and see", "the listener feedback here in the console."); console.emptyLine(); myButton.addListener(new GpioPinListenerDigital() { @Override public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
myButton.addListener(listener); myInput.addListener(listener); myButton.addTrigger(new GpioSetStateTrigger(PinState.HIGH, myRelays[0], PinState.HIGH)); myButton.addTrigger(new GpioSetStateTrigger(PinState.LOW, myRelays[0], PinState.LOW)); myButton.addTrigger(new GpioSyncStateTrigger(myRelays[1])); myButton.addTrigger(new GpioSyncStateTrigger(myRelays[2])); myButton.addTrigger(new GpioPulseStateTrigger(PinState.HIGH, myRelays[3], 1000));
input.setShutdownOptions(true); input.addListener(new GpioPinListenerDigital() { @Override public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) { System.out.println("You can connect pin [" + input.getName() + "] to +3VDC to capture input state changes.");
input.setDebounce(500);; input.addTrigger(new IFTTTMakerChannelTrigger( input.setShutdownOptions(true); console.println("Successfully provisioned [" + input + "] with PULL resistance = [" + input.getPullResistance() + "]"); console.emptyLine();
@Override public boolean getValue() { return digitalInputPin.getState().isHigh(); }
pibrella.getInputPin(PibrellaInput.A).isHigh()) .createMetric()) .addMetric(new MetricBuilder("Inputs/b", MetricDataType.Boolean, pibrella.getInputPin(PibrellaInput.B).isHigh()) .createMetric()) .addMetric(new MetricBuilder("Inputs/c", MetricDataType.Boolean, pibrella.getInputPin(PibrellaInput.C).isHigh()) .createMetric()) .addMetric(new MetricBuilder("Inputs/d", MetricDataType.Boolean, pibrella.getInputPin(PibrellaInput.D).isHigh()) .createMetric()) pibrella.getInputPin(PibrellaInput.Button).isHigh()) .createMetric()) .addMetric(new MetricBuilder("button count",
myButton.addTrigger(new GpioBlinkStateTrigger(PinState.HIGH, myLed, 250)); myButton.addTrigger(new GpioBlinkStopStateTrigger(PinState.LOW, myLed));
int pinDebounceForState = dip.getDebounce(state);
PinState myButtonState = myButton.getState(); boolean buttonPressed = myButton.isHigh(); System.out.println("Current buttonPressed: " + buttonPressed); myButton.addListener(new GpioUsageExampleListener()); myButton.addTrigger(new GpioSyncStateTrigger(myLed));
myButton.setShutdownOptions(true); myButton.addListener(new GpioPinListenerDigital() { @Override public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {