Members
-
<readonly> isOn :boolean
-
Description
If the RGB is onDetails
-
<readonly> isRunning :boolean
-
Description
If the RGB is pulsing, blinking or running an animationDetails
-
<readonly> isAnode :boolean
-
Description
If the RGB is wired for common anodeDetails
-
<readonly> values :Array.<number>
-
Description
The current RGB valuesDetails
Methods
-
configure( options ) → {RGB}
-
Description
Configure an RGB LEDParameters
Name Type Description options
object Device configuration options Name Type Attributes Default Description sink
number <optional> false True if an element is common anode Returns
Examples
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); rgb.blink();
Details
-
color( red [, green [, blue ] ] ) → {RGB}
-
Description
Control an RGB LED's color value. Accepts Hexadecimal strings, an array of color values, and RGB object or a separate argument for each color.Parameters
Name Type Attributes Description red
String | Array | Object | Number Hexadecimal color string, Array of color values, RGB object {red, green, blue}, or the value of the red channel [0, 1] green
Number <optional> The value of the green channel [0, 1] blue
Number <optional> The value of the blue channel [0, 1] Returns
Examples
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399");
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("rgb(0.4, 0.2, 0.6)");
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("rgba(0.4, 0.2, 0.6, 50%)");
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color([0.4, 0.2, 0.6]);
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color({ red: 0.4, green: 0.2, blue: 0.6 });
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color(0.4, 0.2, 0.6);
Details
-
on() → {RGB}
-
Description
Turn an RGB LED on with whatever the current color value isReturns
Examples
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.on(); // Default color is white
Details
-
off() → {RGB}
-
Description
Turn an RGB LED offReturns
Examples
import RGB from "j5e/rgb"; import {timer} from "j5e/fn"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); time.setTimeout(function() { rgb.off(); }, 5000);
Details
-
toggle() → {RGB}
-
Description
Toggle the on/off state of an RGB LEDReturns
Examples
import RGB from "j5e/rgb"; import {timer} from "j5e/fn"; const rgb = await new RGB([13, 12, 14]); rgb.toggle(); // Turns RGB LED on time.setTimeout(function() { rgb.toggle(); // Turns it off }, 5000);
Details
-
blink( duration, callback ) → {RGB}
-
Description
Blink an RGB LED on a fixed intervalParameters
Name Type Default Description duration
Number 100 Time in ms on, time in ms off callback
function Method to call on blink Returns
Examples
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); rgb.blink();
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); rgb.blink(5000);
Details
-
fade( val [, time [, callback ] ] ) → {RGB}
-
Description
fade Fade an RGB LED from its current value to a new valueParameters
Name Type Attributes Default Description val
Array.<Number> | String | Object Hexadecimal color string, CSS color name, Array of color values, RGB object {red, green, blue} time
Number <optional> 1000 Time in ms that a fade will take callback
function <optional> A function to run when the fade is complete Returns
Examples
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.fade("#663399");
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.fade("#663399", 3000);
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.fade("#663399", 3000, function() { rgb.blink(); });
Details
-
fadeIn( [ time [, callback ] ] ) → {RGB}
-
Description
Fade an RGB LED to full brightnessParameters
Name Type Attributes Default Description time
Number <optional> 1000 Time in ms that a fade will take callback
function <optional> A function to run when the fade is complete Returns
Examples
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.fadeIn(500);
Details
-
fadeOut( [ time [, callback ] ] ) → {RGB}
-
Description
Fade an RGB LED offParameters
Name Type Attributes Default Description time
Number <optional> 1000 Time in ms that a fade will take callback
function <optional> A function to run when the fade is complete Returns
Examples
<caption>Fade out an RGB LED over half a second import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); rgb.fadeOut(500);
Details
-
pulse( duration, callback ) → {RGB}
-
Description
Pulse an RGB LED on a fixed intervalParameters
Name Type Default Description duration
Number 1000 Time in ms on, time in ms off callback
function Method to call on pulse Returns
Examples
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); rgb.pulse();
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); rgb.pulse(5000);
Details
-
animate( options ) → {RGB}
-
Description
Animate an RGB LEDParameters
Name Type Description options
Object (See j5e's Timeline and Tweening Tools) Returns
Examples
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.animate({ duration: 4000, cuePoints: [0, 0.33, 0.66, 1], keyFrames: ["#000000", "#FF0000", "#00FFFF", "#FFFFFF"], loop: true, metronomic: true });
Details
-
stop() → {RGB}
-
Description
Stop the RGB LED from pulsing, blinking, fading, or animatingReturns
Examples
import RGB from "j5e/rgb"; import {timer} from "j5e/fn"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); rgb.pulse(250); timer.setTimeout(function() { rgb.stop(); }, 5000);
Details