Members
-
<readonly> isOn :boolean
-
Description
Whether current is flowing. This does not necessarily mean the motor is turning.Details
-
<readonly> currentSpeed :number
-
Description
The Motor's current speedDetails
-
<readonly> enabled :boolean
-
Description
Whether the motor is enabledDetails
-
<readonly> direction :boolean
-
Description
The current directionDetails
Methods
-
configure( options ) → {Motor}
-
Description
Configure a MotorParameters
Name Type Description optionsobject Device configuration options Name Type Attributes Default Description enabledboolean <optional> true Sets the enabled state of a motor thresholdnumber <optional> 0.11 The minimum speed [0, 1] that will make the motor move invertPWMboolean <optional> false When true, PWM values will be inverted when directional motor is in reverse Returns
Examples
import Motor from "j5e/motor"; const motor = await new Motor(12); motor.configure({ enabled: false }); motor.forward(); // No signal is sentDetails
-
enable() → {Motor}
-
Description
Enable a motor. If there is an enable pin, set its value to highReturns
Examples
Enable a motor
import Motor from "j5e/motor"; const motor = await new Motor([13, 12]); motor.disable(); window.setTimeout(() => { motor.enable(); }, 5000);Details
-
disable() → {Motor}
-
Description
Disable a motor. If there is an enable pin, set its value to lowReturns
Examples
Disable a motor
import Motor from "j5e/motor"; const motor = await new Motor([13, 12]); motor.disable();Details
-
start( speed ) → {Motor}
-
Description
Start the motorParameters
Name Type Description speednumber Speed [0, 1] Returns
Details
-
stop() → {Motor}
-
Description
Stop the motorReturns
Details
-
resume() → {Motor}
-
Description
Resumes moving the motor after stop, brake or disable at the most recent set speedReturns
Details
-
brake( [ duration ] ) → {Motor}
-
Description
Brakes the motor - Note that not all motor controllers support braking. If there is no brake pin, brake() behaves the same as stop() and the motor will coast to a stopParameters
Name Type Attributes Description durationnumber <optional> Time in millseconds to hold the brake Returns
Details
-
release() → {Motor}
-
Description
Releases the brake and calls resumeReturns
Details
-
fwd() → {Motor}
-
Description
Alias to forwardReturns
Details
-
forward( [ speed ] ) → {Motor}
-
Description
Set the motor to spin forward. Note that "forward" is an arbitrary label. What it really means is that if they exist, the dir pin will be set low and cdir will be set highParameters
Name Type Attributes Default Description speednumber <optional> 1 The speed expressed as a value from 0 to 1 Returns
Details
-
rev() → {Motor}
-
Description
Alias to reverseReturns
Details
-
reverse( [ speed ] ) → {Motor}
-
Description
Set the motor to spin in reverse. Note that "reverse" is an arbitrary label. What it really means is that if they exist, the dir pin will be set high and cdir will be set lowParameters
Name Type Attributes Default Description speednumber <optional> 1 The speed expressed as a value from 0 to 1 Returns
Details
