Class ServoMotorHelper
java.lang.Object
com.opensourcewithslu.outputdevices.ServoMotorHelper
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
ConstructorsConstructorDescriptionServoMotorHelper(com.pi4j.io.pwm.Pwm servoMotor) Constructs a new ServoMotorHelper. -
Method Summary
Modifier and TypeMethodDescriptionvoiddisable()Disables the servo motor, effectively stopping any ongoing PWM signal.voidenable()Enables the servo motor by setting an initial duty cycle and frequency.booleanReturns the current state of the servo motor.voidsetAngle(int angle) Sets the servo motor to a specific angle.
-
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.
-
isEnabled
public boolean isEnabled()Returns the current state of the servo motor.- Returns:
- true if the servo motor is enabled, false otherwise.
-