java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.VibrationMotorComponent
Implementation of the CrowPi vibration motor 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
ConstructorDescriptionVibrationMotorComponent
(com.pi4j.context.Context pi4j) Creates a new vibration motor component using the default pin.VibrationMotorComponent
(com.pi4j.context.Context pi4j, int pin) Creates a new vibration motor 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
off()
Sets the vibration motor to offvoid
on()
Sets the vibration motor to on.void
pulse
(int interval) Enables the vibration motor a specified time in millisecondsvoid
setState
(boolean on) Set the vibration motor on or off depending on the boolean argument.boolean
toggle()
Toggle the vibration motor 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
-
VibrationMotorComponent
public VibrationMotorComponent(com.pi4j.context.Context pi4j) Creates a new vibration motor component using the default pin.- Parameters:
pi4j
- Pi4J context
-
VibrationMotorComponent
public VibrationMotorComponent(com.pi4j.context.Context pi4j, int pin) Creates a new vibration motor component with a custom BCM pin.- Parameters:
pi4j
- Pi4J contextpin
- Custom BCM pin address
-
-
Method Details
-
setState
public void setState(boolean on) Set the vibration motor on or off depending on the boolean argument.- Parameters:
on
- Sets the relay to on (true) or off (false)
-
on
public void on()Sets the vibration motor to on. -
off
public void off()Sets the vibration motor to off -
toggle
public boolean toggle()Toggle the vibration motor state depending on its current state.- Returns:
- Return true or false according to the new state of the vibration motor.
-
pulse
public void pulse(int interval) Enables the vibration motor a specified time in milliseconds- Parameters:
interval
- How long the vibration motor is enabled in millis
-
getDigitalOutput
protected com.pi4j.io.gpio.digital.DigitalOutput getDigitalOutput()Returns the instance of the digital output- Returns:
- DigitalOutput instance of the vibration motor
-
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 vibration motor- Returns:
- Return Digital Input configuration
-