new <async> RGB( io )

Description
The RGB class allows for control of RGB LED's
Parameters
Name Type Description
io Array.<number> | Array.<string> | Array.<object> | object An array of pin identifiers or IO Options in RGB order, or an RGB IO options object (See Instantiating a Device)
Name Type Attributes Description
red object <optional>
Pin identifier or IO Options for the red channel
green object <optional>
Pin identifier or IO Options for the green channel
blue object <optional>
Pin identifier or IO Options for the blue channel
Examples

Using an array of pin numbers

import RGB from "j5e/rgb";
			
			const rgb = await new RGB([13, 12, 14]);
			rgb.color("#663399");
			rgb.blink();

Using an array of pin identifiers

import RGB from "j5e/rgb";
			
			const rgb = await new RGB(["A1", "A3", "A4"]);
			rgb.color("#663399");
			rgb.blink();

Using an array of option objects

import RGB from "j5e/rgb";
			import PCA9685 from "PCA9685Expander"
			
			const rgb = await new RGB([
			  { pin: 0, io: PCA9685 },
			  { pin: 1, io: PCA9685 },
			  { pin: 2, io: PCA9685 }
			]);
			rgb.color("#663399");
			rgb.blink();

Using an RGB options object

import RGB from "j5e/rgb";
			import PCA9685 from "PCA9685Expander"
			
			const rgb = await new RGB({
			  red: 0,
			  green: {
			    io: PCA9685
			    pin: 1
			  },
			  blue: 3
			});
			rgb.color("#663399");
			rgb.blink();
Details

Members


<readonly> isOn :boolean

Description
If the RGB is on
Details
boolean

<readonly> isRunning :boolean

Description
If the RGB is pulsing, blinking or running an animation
Details
boolean

<readonly> isAnode :boolean

Description
If the RGB is wired for common anode
Details
boolean

<readonly> values :Array.<number>

Description
The current RGB values
Details
Array.<number>

Methods


configure( options ) → {RGB}

Description
Configure an RGB LED
Parameters
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
The instance on which the method was called
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 is
Returns
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 off
Returns
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 LED
Returns
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

Description
Blink an RGB LED on a fixed interval
Parameters
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 value
Parameters
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 brightness
Parameters
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 off
Parameters
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 interval
Parameters
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 LED
Parameters
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 animating
Returns
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