new <async> LED( io )

Description
The LED class allows for control of Light Emitting Diodes
Parameters
Name Type Description
io number | string | object Pin identifier or IO Options (See Instantiating a Device)
Examples

Using a pin number

import LED from "j5e/led";
			
			const led = await new LED(12);
			led.on();

Using a pin identifier string

import LED from "j5e/led";
			
			const led = await new LED("A1");
			led.on();

Using device options

import LED from "j5e/led";
			
			const led = await new LED(12);
			led.configure({
			  pwm: true
			});
			led.on();
Details

Members


<readonly> value :number

Description
The current value of the LED
Details
number

<readonly> isOn :boolean

Description
Wether the LED is on
Details
boolean

<readonly> isRunning :boolean

Description
True if the LED is blinking, pulsing or animating
Details
boolean

Methods


configure( options ) → {LED}

Description
Configure an LED
Parameters
Name Type Description
options object Device configuration options
Name Type Attributes Default Description
sink number <optional>
false True if an element is wired for sink drive
Returns
The instance on which the method was called
Examples
import LED from "j5e/led";
			
			const led = await new LED(14);
			led.configure({
			  sink: true
			});
			
			// With sink: true, led.on() sets pin 14 low
			led.on();
Details

on() → {LED}

Description
Turn an led on
Returns
The instance on which the method was called
Examples
import LED from "j5e/led";
			
			const led = await new LED(12);
			led.on();
Details

off() → {LED}

Description
Turn an led off
Returns
Examples
import LED from "j5e/led";
			import {timer} from "j5e/fn";
			
			const led = await new LED(12);
			led.on();
			
			// Wait one second and turn the led off
			timer.setTimeout(function() {
			  led.off();
			}, 1000);
Details

toggle() → {LED}

Description
Toggle the on/off state of an led
Returns
Examples
import LED from "j5e/led";
			import {timer} from "j5e/fn";
			
			const led = await new LED(12);
			led.toggle(); // It's on!
			
			// Wait one second and turn the led off
			timer.setTimeout(function() {
			  led.toggle(); // It's off!
			}, 1000)
Details

Description
Blink the 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
import LED from "j5e/led";
			
			const led = await new LED(12);
			led.blink(1000);
Details

brightness( value ) → {LED}

Description
Set the brightness of an led
Parameters
Name Type Description
value Number Brightness value [0, 1]
Returns
Examples
import LED from "j5e/led";
			
			const led = await new LED(12, {
			  pwm: true
			});
			led.brightness(0.5);
Details

intensity( value ) → {LED}

Description
Set the brightness of an led 0-100
Parameters
Name Type Description
value Integer Brightness value [0, 100]
Returns
Examples
import LED from "j5e/led";
			
			const led = await new LED(12, {
			  pwm: true
			});
			led.intensity(50);
Details

fade( val [, time [, callback ] ] ) → {LED}

Description
Fade an led from its current value to a new value (Requires ```pwm: true```)
Parameters
Name Type Attributes Default Description
val Number Target brightness value
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 LED from "j5e/led";
			
			const led = await new LED(12, {
			  pwm: true
			});
			led.fade(512);
Details

fadeIn( [ time [, callback ] ] ) → {LED}

Description
fadeIn Fade an led in to full brightness (Requires ```pwm: true```)
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 LED to full brightness over half a second

import LED from "j5e/led";
			
			const led = await new LED(12, {
			  pwm: true
			});
			led.fadeIn(500);
Details

fadeOut( [ time [, callback ] ] ) → {LED}

Description
fadeOut Fade an led out until it is off (Requires ```pwm: true```)
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 LED out over half a second

import LED from "j5e/led";
			
			const led = await new LED(12, {
			  pwm: true
			});
			led.on();
			led.fadeOut(500);
Details

pulse( [ time [, callback ] ] ) → {LED}

Description
Pulse the LED in and out in a loop with specified time using ```inOutSine``` easing (Requires ```pwm: true```)
Parameters
Name Type Attributes Default Description
time number <optional>
1000 Time in ms that a fade in/out will elapse
callback function <optional>
A function to run each time the direction of pulse changes
Returns
Examples

Pulse an LED on a half second interval

import LED from "j5e/led";
			
			const led = await new LED(12, {
			  pwm: true
			});
			led.pulse(500);
Details

animate( options ) → {LED}

Description
Animate the LED by passing in a segment options object
Parameters
Name Type Description
options Object (See j5e's Timeline and Tweening Tools)
Returns
Examples

Animate an LED using an animation segment options object

import LED from "j5e/led";
			
			const led = await new LED(12, {
			  pwm: true
			});
			led.animate({
			  duration: 4000,
			  cuePoints: [0,  0.33, 0.66, 1],
			  keyFrames: [0, 0.75, 0.25, 1],
			  loop: true,
			  metronomic: true
			});
Details

stop() → {LED}

Description
stop Stop the led from blinking, pulsing, fading, or animating
Returns
Examples
Pulse an LED and then stop after five seconds
			import {timer} from "j5e/fn";
			import LED from "j5e/led";
			
			const led = await new LED(12, {
			  pwm: true
			});
			led.pulse(500);
			
			// Stop pulsing after five seconds
			timer.setTimeout(function() {
			  led.stop();
			}, 5000);
Details