Package com.diozero.devices
Class Servo
- java.lang.Object
-
- com.diozero.api.GpioDevice
-
- com.diozero.devices.Servo
-
- All Implemented Interfaces:
DeviceInterface
,OutputDeviceInterface
,AutoCloseable
public class Servo extends GpioDevice implements OutputDeviceInterface
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Servo.Array
static class
Servo.OutputDeviceUnit
static class
Servo.Trim
-
Field Summary
-
Fields inherited from class com.diozero.api.GpioDevice
pinInfo
-
-
Constructor Summary
Constructors Constructor Description Servo(int gpio, float initialPulseWidthMs)
Servo(int gpio, float initialPulseWidthMs, int pwmFrequency)
Servo(int gpio, float initialPulseWidthMs, int pwmFrequency, Servo.Trim trim)
Servo(int gpio, float initialPulseWidthMs, Servo.Trim trim)
Servo(PwmOutputDeviceFactoryInterface pwmDeviceFactory, int gpio, float initialPulseWidthMs, int pwmFrequency)
Servo(PwmOutputDeviceFactoryInterface pwmDeviceFactory, int gpio, float initialPulseWidthMs, int pwmFrequency, Servo.Trim trim)
Servo(PwmOutputDeviceFactoryInterface pwmDeviceFactory, PinInfo pinInfo, float initialPulseWidthMs, int pwmFrequency, Servo.Trim trim)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
centre()
void
close()
Close this devicefloat
getAngle()
Get the current servo angle where 90 degrees is the middle positionServo.OutputDeviceUnit
getOutputDeviceUnit()
float
getPulseWidthMs()
Get the current servo pulse width in millisecondsint
getPwmFrequency()
float
getValue()
void
max()
void
min()
void
setAngle(float angle)
Turn the servo to the specified angle where 90 is the middle positionServo
setInverted(boolean inverted)
Servo
setOutputDeviceUnit(Servo.OutputDeviceUnit outputDeviceUnit)
void
setPulseWidthMs(float pulseWidthMs)
Set the servo pulse width in millisecondsvoid
setValue(float value)
Sets the output value of the device.-
Methods inherited from class com.diozero.api.GpioDevice
getGpio
-
-
-
-
Constructor Detail
-
Servo
public Servo(int gpio, float initialPulseWidthMs) throws RuntimeIOException
- Throws:
RuntimeIOException
-
Servo
public Servo(int gpio, float initialPulseWidthMs, Servo.Trim trim) throws RuntimeIOException
- Throws:
RuntimeIOException
-
Servo
public Servo(int gpio, float initialPulseWidthMs, int pwmFrequency) throws RuntimeIOException
- Throws:
RuntimeIOException
-
Servo
public Servo(int gpio, float initialPulseWidthMs, int pwmFrequency, Servo.Trim trim) throws RuntimeIOException
- Throws:
RuntimeIOException
-
Servo
public Servo(PwmOutputDeviceFactoryInterface pwmDeviceFactory, int gpio, float initialPulseWidthMs, int pwmFrequency) throws RuntimeIOException
- Throws:
RuntimeIOException
-
Servo
public Servo(PwmOutputDeviceFactoryInterface pwmDeviceFactory, int gpio, float initialPulseWidthMs, int pwmFrequency, Servo.Trim trim) throws RuntimeIOException
- Throws:
RuntimeIOException
-
Servo
public Servo(PwmOutputDeviceFactoryInterface pwmDeviceFactory, PinInfo pinInfo, float initialPulseWidthMs, int pwmFrequency, Servo.Trim trim) throws RuntimeIOException
- Throws:
RuntimeIOException
-
-
Method Detail
-
getOutputDeviceUnit
public Servo.OutputDeviceUnit getOutputDeviceUnit()
-
setOutputDeviceUnit
public Servo setOutputDeviceUnit(Servo.OutputDeviceUnit outputDeviceUnit)
-
setInverted
public Servo setInverted(boolean inverted)
-
close
public void close()
Description copied from interface:DeviceInterface
Close this device- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDeviceInterface
-
getPwmFrequency
public int getPwmFrequency()
-
getValue
public float getValue()
-
setValue
public void setValue(float value)
Description copied from interface:OutputDeviceInterface
Sets the output value of the device.- Specified by:
setValue
in interfaceOutputDeviceInterface
- Parameters:
value
- the value to output
-
getPulseWidthMs
public float getPulseWidthMs()
Get the current servo pulse width in milliseconds- Returns:
- The servo pulse width (milliseconds)
-
setPulseWidthMs
public void setPulseWidthMs(float pulseWidthMs)
Set the servo pulse width in milliseconds- Parameters:
pulseWidthMs
- Servo pulse width (milliseconds)
-
getAngle
public float getAngle()
Get the current servo angle where 90 degrees is the middle position- Returns:
- Servo angle (90 degrees is middle)
-
setAngle
public void setAngle(float angle)
Turn the servo to the specified angle where 90 is the middle position- Parameters:
angle
- Servo angle (90 degrees is middle)
-
min
public void min()
-
max
public void max()
-
centre
public void centre()
-
-