Class ServoMotorHelper

java.lang.Object
com.opensourcewithslu.outputdevices.ServoMotorHelper

public class ServoMotorHelper extends Object
Helper class to control a servo motor using PWM (Pulse Width Modulation). This class provides methods to enable, disable, and set the angle of a servo motor.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ServoMotorHelper(com.pi4j.io.pwm.Pwm servoMotor)
    Constructs a new ServoMotorHelper.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Disables the servo motor, effectively stopping any ongoing PWM signal.
    void
    Enables the servo motor by setting an initial duty cycle and frequency.
    void
    setAngle(int angle)
    Sets the servo motor to a specific angle.

    Methods inherited from class java.lang.Object

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

    • ServoMotorHelper

      public ServoMotorHelper(com.pi4j.io.pwm.Pwm servoMotor)
      Constructs a new ServoMotorHelper.
      Parameters:
      servoMotor - A PWM interface to control the servo motor.
  • Method Details

    • enable

      public void enable()
      Enables the servo motor by setting an initial duty cycle and frequency. The servo motor remains disabled until this method is called.
    • disable

      public void disable()
      Disables the servo motor, effectively stopping any ongoing PWM signal.
    • setAngle

      public void setAngle(int angle)
      Sets the servo motor to a specific angle. This method calculates the necessary pulse width and duty cycle to achieve the specified angle.
      Parameters:
      angle - the target angle for the servo motor, between 0 and 180 degrees.