new <async> Motor( io )

Description
The Motor class allows for control of non-directional DC Motors
Parameters
Name Type Description
io number | string | Array.<number> | Array.<string> | Array.<object> | object A pin identifier or motor IO options object (See Instantiating a Device)
Examples

Using a pin number

import Motor from "j5e/motor";
			
			const motor = await new Motor(12);
			motor.fwd();

Using an options object

import Motor from "j5e/motor";
			
			const motor = await new Motor({
			  pin: 12
			});
			motor.fwd();
Details

Members


<readonly> isOn :boolean

Description
Whether current is flowing. This does not necessarily mean the motor is turning.
Details
boolean

<readonly> currentSpeed :number

Description
The Motor's current speed
Details
number

<readonly> enabled :boolean

Description
Whether the motor is enabled
Details
boolean

<readonly> direction :boolean

Description
The current direction
Details
boolean

Methods


configure( options ) → {Motor}

Description
Configure a Motor
Parameters
Name Type Description
options object Device configuration options
Name Type Attributes Default Description
enabled boolean <optional>
true Sets the enabled state of a motor
threshold number <optional>
0.11 The minimum speed [0, 1] that will make the motor move
invertPWM boolean <optional>
false When true, PWM values will be inverted when directional motor is in reverse
Returns
The instance on which the method was called
Examples
import Motor from "j5e/motor";
			
			const motor = await new Motor(12);
			motor.configure({
			  enabled: false
			});
			motor.forward(); // No signal is sent
Details

enable() → {Motor}

Description
Enable a motor. If there is an enable pin, set its value to high
Returns
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 low
Returns
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 motor
Parameters
Name Type Description
speed number Speed [0, 1]
Returns
Details

stop() → {Motor}

Description
Stop the motor
Returns
Details

resume() → {Motor}

Description
Resumes moving the motor after stop, brake or disable at the most recent set speed
Returns
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 stop
Parameters
Name Type Attributes Description
duration number <optional>
Time in millseconds to hold the brake
Returns
Details

release() → {Motor}

Description
Releases the brake and calls resume
Returns
Details

fwd() → {Motor}

Description
Alias to forward
Returns
Details

forward


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 high
Parameters
Name Type Attributes Default Description
speed number <optional>
1 The speed expressed as a value from 0 to 1
Returns
Details

rev() → {Motor}

Description
Alias to reverse
Returns
Details

reverse


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 low
Parameters
Name Type Attributes Default Description
speed number <optional>
1 The speed expressed as a value from 0 to 1
Returns
Details