Class DebouncedButton

  • All Implemented Interfaces:
    com.diozero.api.DeviceInterface , com.diozero.api.DigitalInputDeviceInterface , com.diozero.api.function.DeviceEventConsumer , java.lang.AutoCloseable , java.util.function.Consumer

    
    public final class DebouncedButton
    extends DebouncedDigitalInputDevice
                        

    Simple extension to get the whenPressed and whenReleased semantics with debounce.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final GpioEventTrigger trigger
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Unit whenPressed(LongConsumer buttonConsumer) Action to perform when the button is pressed.
      final Unit whenReleased(LongConsumer buttonConsumer) Action to perform when the button is released.
      • Methods inherited from class com.diozero.api.DigitalInputDevice

        getName, getPullUpDown, getTrigger, getValue, isActive
      • Methods inherited from class com.diozero.api.DebouncedDigitalInputDevice

        accept, changeDetection, close
      • Methods inherited from class com.diozero.api.GpioDevice

        getGpio
      • Methods inherited from class java.util.function.Consumer

        andThen
      • Methods inherited from class com.diozero.api.GpioInputDevice

        addListener, hasListeners, removeAllListeners, removeListener
      • Methods inherited from class com.diozero.api.AbstractDigitalInputDevice

        isActiveHigh, waitForActive, waitForActive, waitForInactive, waitForInactive, waitForValue, whenActivated, whenDeactivated
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DebouncedButton

        DebouncedButton(Integer gpio, Duration debounceTime, GpioPullUpDown pud, Boolean activeHigh, GpioDeviceFactoryInterface deviceFactory)
      • DebouncedButton

        DebouncedButton(Integer gpio, Duration debounceTime, GpioPullUpDown pud, Boolean activeHigh)
      • DebouncedButton

        DebouncedButton(Integer gpio, Duration debounceTime, GpioPullUpDown pud)
    • Method Detail

      • whenPressed

         final Unit whenPressed(LongConsumer buttonConsumer)

        Action to perform when the button is pressed.

        Parameters:
        buttonConsumer - Callback function to invoke when pressed (long parameter is nanoseconds time).
      • whenReleased

         final Unit whenReleased(LongConsumer buttonConsumer)

        Action to perform when the button is released.

        Parameters:
        buttonConsumer - Callback function to invoke when released (long parameter is nanoseconds time).