Class VibrationMotorComponent

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

public class VibrationMotorComponent extends Component
Implementation of the CrowPi vibration motor 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
    VibrationMotorComponent(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 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
    off()
    Sets the vibration motor to off
    void
    on()
    Sets the vibration motor to on.
    void
    pulse(int interval)
    Enables the vibration motor a specified time in milliseconds
    void
    setState(boolean on)
    Set the vibration motor on or off depending on the boolean argument.
    boolean
    Toggle the vibration motor 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

    • 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 context
      pin - 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 Context
      address - GPIO Address of vibration motor
      Returns:
      Return Digital Input configuration