java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.RelayComponent
Implementation of the CrowPi Relay using GPIO with Pi4J
-
Field Summary
Modifier and TypeFieldDescriptionprotected 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 -
Constructor Summary
ConstructorDescriptionRelayComponent
(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 TypeMethodDescriptionprotected com.pi4j.io.gpio.digital.DigitalOutputConfig
buildDigitalOutputConfig
(com.pi4j.context.Context pi4j, int address) Configure Digital Inputprotected com.pi4j.io.gpio.digital.DigitalOutput
Returns the instance of the digital outputvoid
setState
(boolean on) Set the Relay on or off depending on the boolean argument.void
Sets the relay to offvoid
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
-
Field Details
-
digitalOutput
protected final com.pi4j.io.gpio.digital.DigitalOutput digitalOutputPi4J digital output instance used by this component -
DEFAULT_PIN
protected static final int DEFAULT_PINIf 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 contextaddress
- 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 Contextaddress
- GPIO Address of the relay- Returns:
- Return Digital Input configuration
-