Package com.diozero.devices.motor
Class PwmMotor
java.lang.Object
com.diozero.devices.motor.MotorBase
com.diozero.devices.motor.PwmMotor
- All Implemented Interfaces:
FloatConsumer
,MotorInterface
,Closeable
,AutoCloseable
public class PwmMotor extends MotorBase
Generic bi-directional motor controlled by separate forward / backward PWM output GPIOs
-
Constructor Summary
Constructors Constructor Description PwmMotor(int forwardPwmGpio, int backwardPwmGpio)
PwmMotor(PwmOutputDeviceFactoryInterface deviceFactory, int forwardPwmGpio, int backwardPwmGpio)
-
Method Summary
Modifier and Type Method Description void
backward()
Backward at full speedvoid
backward(float speed)
void
close()
void
forward()
Forward at full speedvoid
forward(float speed)
float
getValue()
Represents the speed of the motor as a floating point value between -1 (full speed backward) and 1 (full speed forward).boolean
isActive()
void
stop()
Methods inherited from class com.diozero.devices.motor.MotorBase
accept, addListener, removeListener, reverse, setValue, whenBackward, whenForward, whenStop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.diozero.api.function.FloatConsumer
andThen
-
Constructor Details
-
PwmMotor
- Throws:
RuntimeIOException
-
PwmMotor
public PwmMotor(PwmOutputDeviceFactoryInterface deviceFactory, int forwardPwmGpio, int backwardPwmGpio) throws RuntimeIOException- Throws:
RuntimeIOException
-
-
Method Details
-
close
public void close() -
forward
Forward at full speed- Throws:
RuntimeIOException
- if an I/O error occurs
-
forward
- Parameters:
speed
- Range 0..1- Throws:
RuntimeIOException
- if an I/O error occurs
-
backward
Backward at full speed- Throws:
RuntimeIOException
- if an I/O error occurs
-
backward
- Parameters:
speed
- Range 0..1- Throws:
RuntimeIOException
- if an I/O error occurs
-
stop
- Throws:
RuntimeIOException
-
getValue
Represents the speed of the motor as a floating point value between -1 (full speed backward) and 1 (full speed forward).- Returns:
- current relative motor speed
- Throws:
RuntimeIOException
- if an I/O error occurs
-
isActive
- Throws:
RuntimeIOException
-