Members
-
<readonly> history
-
Description
The last five position updatesProperties
Name Type Description timestamp
date Timestamp of position update target
number The user requested position degrees
number The actual position (factors in offset and invert) pulseWidth
number The corrected pulseWidth (factors in offset and invert) Returns
Details
-
<readonly> last
-
Description
The most recent position updateProperties
Name Type Description timestamp
date Timestamp of position update target
number The user requested position degrees
number The actual position (factors in offset and invert) pulseWidth
number The corrected pulseWidth (factors in offset and invert) Returns
Details
-
<readonly> position
-
Description
The most recent request and corrected position (factors in offset and invert)Returns
Details
Methods
-
configure( options ) → {Servo}
-
Description
Configure a ServoParameters
Name Type Description options
object Device configuration options Name Type Attributes Default Description pin
number | string <optional> If passing an object, a pin number or pin identifier io
string | constructor <optional> builtin/pwm If passing an object, a string specifying a path to the IO provider or a constructor type
string <optional> "standard" Type of servo ("standard" or "continuous") pwmRange
Array.<number> <optional> [600, 2400] The pulse width range in microseconds deadband
Array.<number> <optional> [90,90] The degree range at which a continuos motion servo will not turn range
Array.<number> <optional> [0, 180] The allowed range of motion in degrees deviceRange
Array.<number> <optional> [0, 180] The physical range (throw) of the servo in degrees startAt
number <optional> "Any value within options.range" The desired start position of the servo offset
number <optional> 0 Adjust the position of the servo for trimming invert
boolean <optional> false Reverses the direction of rotation center
boolean <optional> false Center the servo on instantiation Returns
Examples
import Servo from "j5e/servo"; const servo = await new Servo({ pin: 12 }); servo.configure({type: "continuous"}); servo.cw();
Details
-
to( degrees [, time [, rate ] ] ) → {Servo}
-
Description
Set the servo's position to given degree over time.Parameters
Name Type Attributes Default Description degrees
Number | Object Degrees to move servo to or an animation object (See j5e's Timeline and Tweening Tools) time
Number <optional> Time to spend in motion. If degrees is a number and this value is ommitted, the servo will move to the requested degrees as quickly as possible. rate
Number <optional> 20 The target frame rate of the motion transiton Returns
Examples
import Servo from "j5e/servo"; const servo = await new Servo(12); servo.to(180);
import Servo from "j5e/servo"; const servo = await new Servo(12); servo.to(180, 1000);
import Servo from "j5e/servo"; import { inOutQuad } from "j5e/easing"; const servo = await new Servo(12); servo.to({ duration: 1000, cuePoints: [0, 1.0], keyFrames: [ null, 180 ], easing: inOutQuad });
Details
-
step( degrees [, time ] ) → {Servo}
-
Description
Update the servo position by specified degrees (over time)Parameters
Name Type Attributes Description degrees
Number Degrees to turn servo to. time
Number <optional> Time to spend in motion. Returns
Examples
import Servo from "j5e/servo"; const servo = await new Servo(12); // The servo's default position is 90 degrees servo.step(30);
import Servo from "j5e/servo"; const servo = await new Servo(12); // The servo's default position is 90 degrees servo.step(30, 1000);
Details
-
min( [ time ] ) → {Servo}
-
Description
min Set Servo to minimum degrees, defaults to 0degParameters
Name Type Attributes Description time
Number <optional> Time to spend in motion. Returns
Examples
import Servo from "j5e/servo"; const servo = await new Servo(12); servo.min();
import Servo from "j5e/servo"; const servo = await new Servo(12); servo.min(1000);
Details
-
max( [ time ] ) → {Object}
-
Description
Set Servo to maximum degrees, defaults to 180degParameters
Name Type Attributes Description time
Number <optional> Time to spend in motion. Returns
Examples
import Servo from "j5e/servo"; const servo = await new Servo(12); servo.max();
import Servo from "j5e/servo"; const servo = await new Servo(12); servo.max(1000);
Details
-
center( [ time ] ) → {Object}
-
Description
Set Servo to centerpoint, defaults to 90degParameters
Name Type Attributes Description time
Number <optional> Time to spend in motion. Returns
Examples
import Servo from "j5e/servo"; import { timer } from "j5e/fn"; const servo = await new Servo(12); servo.to(180); timer.setTimeout(function() { servo.center(); }, 1000);
import Servo from "j5e/servo"; import { timer } from "j5e/fn"; const servo = await new Servo(12); servo.to(180); timer.setTimeout(function() { servo.center(1000); }, 1000);
Details
-
home() → {Servo}
-
Description
Return Servo to its startAt positionReturns
Examples
import Servo from "j5e/servo"; import { timer } from "j5e/fn"; const servo = await new Servo(12); servo.to(180); timer.setTimeout(function() { servo.home(); }, 1000);
Details
-
sweep( opts ) → {Servo}
-
Description
Sweep the servo between min and max or provided rangeParameters
Name Type Description opts
Array | Object An array describing the range of the sweep in degrees or an animation segment options object Returns
Examples
import Servo from "j5e/servo"; const servo = await new Servo(12); servo.sweep([10, 170])); example <caption>Sweep a servo back and forth between 10° to 170° with inOutCirc easing</caption> import Servo from "j5e/servo"; import {inOutCirc} from "j5e/easing"; const servo = await new Servo(12); servo.sweep({ keyFrames: [10, 170], cuePoints: [0, 1], easing: inOutCirc });
Details
-
stop()
-
Description
Stop a moving servo return {Servo}Examples
import Servo from "j5e/servo"; const servo = await new Servo(12); servo.sweep([10, 170])); timer.setTimeout(function() { servo.stop(); }, 2000);
Details
-
cw( speed ) → {Servo}
-
Description
Move a continuous rotation servo clockwiseParameters
Name Type Default Description speed
number 1 Speed between 0 and 1. Returns
Examples
import Servo from "j5e/servo"; const servo = await new Servo({ pin: 12, type: "continuous"}); servo.cw();
import Servo from "j5e/servo"; const servo = await new Servo({ pin: 12, type: "continuous"}); servo.cw(0.5);
Details
-
ccw( speed ) → {Servo}
-
Description
Move a continuous rotation servo counter-clockwiseParameters
Name Type Default Description speed
number 1 Speed between 0 and 1. Returns
Examples
import Servo from "j5e/servo"; const servo = await new Servo({ pin: 12, type: "continuous"}); servo.ccw();
import Servo from "j5e/servo"; const servo = await new Servo({ pin: 12, type: "continuous"}); servo.ccw(0.5);
Details
-
on( event, listener )
-
Description
Create an event listenerParameters
Name Type Description event
string The name of the event to listen for listener
function A callback to run when the event is fired. Details
-
removeListener( event, listener )
-
Description
Remove an event listenerParameters
Name Type Description event
string The name of the event that we are removing a listener from listener
function The callback that we are removing Details
-
once( event, listener )
-
Description
Create an event listener that will only fire one time.Parameters
Name Type Description event
string The name of the event to listen for listener
function A callback to run when the event is fired. Details