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
Use a hex value to make it purple
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399");
Use an RGB String to make it purple
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("rgb(0.4, 0.2, 0.6)");
Use an RGBA String to make it darker purple
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("rgba(0.4, 0.2, 0.6, 50%)");
Use an array to make it purple
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color([0.4, 0.2, 0.6]);
Use an object to make it purple
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color({ red: 0.4, green: 0.2, blue: 0.6 });
Use seperate Red, Green, and Blue arguments to make it purple
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
Make it on
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
Make it purple for five seconds
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
Make it purple for five seconds
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
Make it blink
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); rgb.blink();
Make it blink slowly
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
Fade on to purple
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.fade("#663399");
Fade on to purple over 3 seconds
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.fade("#663399", 3000);
Fade on to purple over 3 seconds and then blink
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
Fade an RGB LED to white over half a second
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
Make it pulse
import RGB from "j5e/rgb"; const rgb = await new RGB([13, 12, 14]); rgb.color("#663399"); rgb.pulse();
Make it pulse slowly
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
Animate an RGB LED using an animation segment options object
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
Make it pulse for five seconds and then stop
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