Led RGB - lyzadanger/johnny-five GitHub Wiki
The Led.RGB
class constructs objects that represent an RGB Led.
- options
Property Name | Type | Value(s) | Description | Required |
---|---|---|---|---|
pins | Object | ``` { red: 3, green: 5, blue: 6 } ``` | Sets the pins for each corresponding color | yes |
- pins
Property Name | Type | Value(s) | Description | Required |
---|---|---|---|---|
red | Number | Any PWM pin on board | Sets the Led's red pin | yes |
green | Number | Any PWM pin on board | Sets the Led's green pin | yes |
blue | Number | Any PWM pin on board | Sets the Led's blue pin | yes |
- pins An Array containing the respective values for the red, green and blue pins.
var digital = new five.Led.RGB([9, 10, 11]);
{
red: Led object
green: Led object
blue: Led object
}
var five = require("johnny-five");
five.Board().on("ready", function() {
var a = new five.Led.RGB([ 9, 10, 11 ]);
var b = new five.Led.RGB({
pins: {
red: 3,
green: 5,
blue: 6
}
});
this.repl.inject({
a: a,
b: b
});
a.pulse();
b.pulse();
});
-
on() Turn the led on.
var led = new five.Led.RGB([9, 10, 11]); led.on();
-
off() Turn the Led off.
var led = new five.Led.RGB([9, 10, 11]); led.off();
-
color(value) Sets the Led color.
var led = new five.Led.RGB([9, 10, 11]); led.color("#ff00ff");
-
toggle() Toggle the current state, if on then turn off, if off then turn on.
var led = new five.Led.RGB([9, 10, 11]); led.toggle();
-
strobe(ms) Strobe/Blink the Led on/off in phases over
ms
. This is an interval operation and can be stopped by callingled.stop()
, however that will not necessarily turn it "off". Defaults to 500ms.var led = new five.Led.RGB([9, 10, 11]); // Strobe on-off in 500ms phases led.strobe(500);
-
brightness(0-255) Set the brightness of led. This operation will only work with Leds attached to PWM pins.
var led = new five.Led.RGB([9, 10, 11]); // This will set the brightness to about half led.brightness(128);
-
fadeIn(ms) Fade in from current brightness over
ms
. This is an interval operation and can be stopped by callingpin.stop()
, however that will not necessarily turn it "off". This operation will only work with Leds attached to PWM pins.var led = new five.Led.RGB([9, 10, 11]); // Fade in over 500ms. led.fadeIn(500);
-
fadeOut(ms) Fade out from current brightness over
ms
. This is an interval operation and can be stopped by callingpin.stop()
, however that will not necessarily turn it "off". This operation will only work with Leds attached to PWM pins.var led = new five.Led.RGB([9, 10, 11]); // Fade out over 500ms. led.fadeOut(500);
-
pulse(ms) Pulse the Led in phases from on to off over
ms
time. This is an interval operation and can be stopped by callingpin.stop()
, however that will not necessarily turn it "off". This operation will only work with Leds attached to PWM pins.var led = new five.Led.RGB([9, 10, 11]); // Pulse from on to off in 500ms phases led.pulse(500);
-
stop(ms) For interval operations, call
stop
to stop the interval.stop
does not necessarily turn "off" the Led, in order to fully shut down an Led, a program must callstop().off()
. This operation will only work with Leds attached to PWM pins.var led = new five.Led.RGB([9, 10, 11]); // Pulse from on to off in 500ms phases led.pulse(500); ...Sometime later... led.stop();
Led objects are output only and therefore do not emit any events.