Package com.diozero.devices.motor
Class MotorBase
- java.lang.Object
-
- com.diozero.devices.motor.MotorBase
-
- All Implemented Interfaces:
DeviceInterface
,MotorInterface
,AutoCloseable
- Direct Known Subclasses:
PiconZeroMotor
,PwmMotor
,TB6612FNGMotor
public abstract class MotorBase extends Object implements MotorInterface
-
-
Constructor Summary
Constructors Constructor Description MotorBase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(MotorEventListener listener)
void
removeListener(MotorEventListener listener)
void
reverse()
Reverse direction of the motorsvoid
setValue(float value)
Set the speed of the motor as a floating point value between -1 (full speed backward) and 1 (full speed forward)protected void
valueChanged(float value)
void
whenBackward(Action action)
void
whenForward(Action action)
void
whenStop(Action action)
-
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.DeviceInterface
close
-
-
-
-
Method Detail
-
reverse
public void reverse() throws RuntimeIOException
Reverse direction of the motors- Specified by:
reverse
in interfaceMotorInterface
- Throws:
RuntimeIOException
- if an I/O error occurs
-
setValue
public void setValue(float value) throws RuntimeIOException
Set the speed of the motor as a floating point value between -1 (full speed backward) and 1 (full speed forward)- Specified by:
setValue
in interfaceMotorInterface
- Parameters:
value
- Range -1 .. 1. Positive numbers for forward, Negative numbers for backward- Throws:
RuntimeIOException
- if an I/O error occurs
-
valueChanged
protected void valueChanged(float value)
-
whenForward
public void whenForward(Action action)
- Specified by:
whenForward
in interfaceMotorInterface
-
whenBackward
public void whenBackward(Action action)
- Specified by:
whenBackward
in interfaceMotorInterface
-
whenStop
public void whenStop(Action action)
- Specified by:
whenStop
in interfaceMotorInterface
-
addListener
public void addListener(MotorEventListener listener)
- Specified by:
addListener
in interfaceMotorInterface
-
removeListener
public void removeListener(MotorEventListener listener)
- Specified by:
removeListener
in interfaceMotorInterface
-
-