Class StepMotorComponent

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

public class StepMotorComponent extends Component
Implementation of the CrowPi Step Motor using GPIO with Pi4J
  • Field Summary

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

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
    StepMotorComponent(com.pi4j.context.Context pi4j)
    Creates a new step motor component with the default pins, steps and pulse duration.
    StepMotorComponent(com.pi4j.context.Context pi4j, int[] addresses, int[][] steps, long pulseMilliseconds)
    Creates a new step motor component with custom pins, steps and pulse duration.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected com.pi4j.io.gpio.digital.DigitalOutputConfig
    buildDigitalOutputConfig(com.pi4j.context.Context pi4j, int address)
    Builds a new digital output configuration for the GPIO step motor pin
    protected com.pi4j.io.gpio.digital.DigitalOutput[]
    Returns an array of all initialized digital outputs for this component
    void
    turnBackward(int steps)
    Turns the step motor backward for the given amount of steps.
    void
    turnDegrees(int degrees)
    Turns the step motor by the given amount of degrees.
    void
    turnForward(int steps)
    Turns the step motor forward for the given amount of steps.

    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
  • Constructor Details

    • StepMotorComponent

      public StepMotorComponent(com.pi4j.context.Context pi4j)
      Creates a new step motor component with the default pins, steps and pulse duration.
      Parameters:
      pi4j - Pi4J context
    • StepMotorComponent

      public StepMotorComponent(com.pi4j.context.Context pi4j, int[] addresses, int[][] steps, long pulseMilliseconds)
      Creates a new step motor component with custom pins, steps and pulse duration.

      The first dimension of steps represents the various steps which are to be executed in order. The second dimension of steps represents which output(s) should be pulsed for the current step. Please note that the second dimension does not store the pin addresses but the index within addresses.

      Parameters:
      pi4j - Pi4J context
      addresses - Array of BCM pin addresses to be driven during steps
      steps - Two-dimensional array containing steps with their associated pins
      pulseMilliseconds - Duration in milliseconds for pulses
  • Method Details

    • turnDegrees

      public void turnDegrees(int degrees)
      Turns the step motor by the given amount of degrees. If a negative value is specified, the motor will automatically turn backward.
      Parameters:
      degrees - Number of degrees to turn for- or backward
    • turnForward

      public void turnForward(int steps)
      Turns the step motor forward for the given amount of steps.
      Parameters:
      steps - Steps to turn forward
    • turnBackward

      public void turnBackward(int steps)
      Turns the step motor backward for the given amount of steps.
      Parameters:
      steps - Steps to turn backward
    • getDigitalOutputs

      protected com.pi4j.io.gpio.digital.DigitalOutput[] getDigitalOutputs()
      Returns an array of all initialized digital outputs for this component
      Returns:
      Digital output instances
    • buildDigitalOutputConfig

      protected com.pi4j.io.gpio.digital.DigitalOutputConfig buildDigitalOutputConfig(com.pi4j.context.Context pi4j, int address)
      Builds a new digital output configuration for the GPIO step motor pin
      Parameters:
      pi4j - Pi4J context
      address - BCM address
      Returns:
      Digital output configuration