Class SoundSensorComponent

    • Field Detail

      • digitalInput

        protected final com.pi4j.io.gpio.digital.DigitalInput digitalInput
        Pi4J digital input instance used by this component
      • DEFAULT_PIN

        protected static final int DEFAULT_PIN
        Default Pin of sound sensor
        See Also:
        Constant Field Values
      • DEFAULT_DEBOUNCE

        protected static final long DEFAULT_DEBOUNCE
        Debounce of input in microseconds
        See Also:
        Constant Field Values
    • Constructor Detail

      • SoundSensorComponent

        public SoundSensorComponent​(com.pi4j.context.Context pi4j)
        Creates a new sound sensor component using the default setup.
        Parameters:
        pi4j - Pi4J context
      • SoundSensorComponent

        public SoundSensorComponent​(com.pi4j.context.Context pi4j,
                                    int address,
                                    long debounce)
        Create sound sensor component with custom parameters
        Parameters:
        pi4j - Pi4J context
        address - Custom BCM pin address
        debounce - Time to debounce the sound sensor in microseconds
    • Method Detail

      • onNoise

        public void onNoise​(SimpleEventHandler handler)
        Sets or disables the handler for the onNoise event. This event gets triggered whenever the sensor registers noise. Only a single event handler can be registered at once.
        Parameters:
        handler - Event handler to call or null to disable
      • isNoisy

        public boolean isNoisy()
        Reads the current sensor state
        Returns:
        Returns true if there is a noise currently registered by the sensor
      • isSilent

        public boolean isSilent()
        Reads the current sensor state
        Returns:
        Returns true if it is silent around the sensor
      • getState

        public SoundSensorComponent.SoundState getState()
        Returns the SoundState of the sensor
        Returns:
        Returns the well-known SoundState according to the current noise level
      • onSilence

        public void onSilence​(SimpleEventHandler handler)
        Sets or disables the handler for the onSilence event. This event gets triggered whenever the sensor is no longer under noise Only a single event handler can be registered at once.
        Parameters:
        handler - Event handler to call or null to disable
      • buildDigitalInputConfig

        protected com.pi4j.io.gpio.digital.DigitalInputConfig buildDigitalInputConfig​(com.pi4j.context.Context pi4j,
                                                                                      int address,
                                                                                      long debounce)
        Configure Digital Input
        Parameters:
        pi4j - PI4J Context
        address - GPIO Address of sound sensor
        Returns:
        Return Digital Input configuration