Class RelayComponent

java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.RelayComponent

public class RelayComponent extends Component
Implementation of the CrowPi Relay using GPIO with Pi4J
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final int
    If no pin is specified by the user, the default BCM pin is used.
    protected final com.pi4j.io.gpio.digital.DigitalOutput
    Pi4J digital output instance used by this component

    Fields inherited from class com.pi4j.crowpi.components.Component

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
    RelayComponent(com.pi4j.context.Context pi4j)
    Creates a new relay component using the default pin.
    RelayComponent(com.pi4j.context.Context pi4j, int address)
    Creates a new buzzer component with a custom BCM pin.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected com.pi4j.io.gpio.digital.DigitalOutputConfig
    buildDigitalOutputConfig(com.pi4j.context.Context pi4j, int address)
    Configure Digital Input
    protected com.pi4j.io.gpio.digital.DigitalOutput
    Returns the instance of the digital output
    void
    setState(boolean on)
    Set the Relay on or off depending on the boolean argument.
    void
    Sets the relay to off
    void
    Sets the relay to on.
    boolean
    Toggle the relay state depending on its current state.

    Methods inherited from class com.pi4j.crowpi.components.Component

    sleep, triggerSimpleEvent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • digitalOutput

      protected final com.pi4j.io.gpio.digital.DigitalOutput digitalOutput
      Pi4J digital output instance used by this component
    • DEFAULT_PIN

      protected static final int DEFAULT_PIN
      If no pin is specified by the user, the default BCM pin is used.
      See Also:
  • Constructor Details

    • RelayComponent

      public RelayComponent(com.pi4j.context.Context pi4j)
      Creates a new relay component using the default pin.
      Parameters:
      pi4j - Pi4J context
    • RelayComponent

      public RelayComponent(com.pi4j.context.Context pi4j, int address)
      Creates a new buzzer component with a custom BCM pin.
      Parameters:
      pi4j - Pi4J context
      address - Custom BCM pin address
  • Method Details

    • setState

      public void setState(boolean on)
      Set the Relay on or off depending on the boolean argument.
      Parameters:
      on - Sets the relay to on (true) or off (false)
    • setStateOn

      public void setStateOn()
      Sets the relay to on.
    • setStateOff

      public void setStateOff()
      Sets the relay to off
    • toggleState

      public boolean toggleState()
      Toggle the relay state depending on its current state.
      Returns:
      Return true or false according to the new state of the relay.
    • getDigitalOutput

      protected com.pi4j.io.gpio.digital.DigitalOutput getDigitalOutput()
      Returns the instance of the digital output
      Returns:
      DigitalOutput instance of the relay
    • buildDigitalOutputConfig

      protected com.pi4j.io.gpio.digital.DigitalOutputConfig buildDigitalOutputConfig(com.pi4j.context.Context pi4j, int address)
      Configure Digital Input
      Parameters:
      pi4j - PI4J Context
      address - GPIO Address of the relay
      Returns:
      Return Digital Input configuration