Everloop
Device Compatibility
Overview
The following sections below will go over how to control the LED array on your MATRIX Device.
Import Statement
const matrix = require("@matrix-io/matrix-lite");
led
.length
Returns the number of LEDs on a MATRIX device.
matrix.led.length;
.set()
Allows you to set the colors of each LED. A string
, object
, array
, or an undefined
value can be given to this function.
// Valid ways to set each LED matrix.led.set("blue"); // color name matrix.led.set("rgb(0,0,255)"); // RGB values matrix.led.set("#0000ff"); // hex values matrix.led.set({r:0,g:0,b:255,w:0}); // objects
Passing in an array allows you to set each individual LED color. However, passing an array that's larger than led.length
will result in an error.
matrix.led.set(['red', 'gold', 'purple', {}, , '#6F41C1', 'rgb(0,0,255)', {g:255}]);
Everloop Examples
const matrix = require("@matrix-io/matrix-lite"); // A single string or object sets all LEDs // Below are different ways of expressing the color blue (number values are from 0-255) matrix.led.set('blue'); matrix.led.set('rgb(0,0,255)'); matrix.led.set('#0000ff'); matrix.led.set({r:0, g:0, b:255, w:0}); // objects can set white
const matrix = require("@matrix-io/matrix-lite"); // Each line below is a valid way of turning the LEDs off matrix.led.set('black'); matrix.led.set([]); matrix.led.set(); matrix.led.set({});
const matrix = require("@matrix-io/matrix-lite"); let everloop = new Array(matrix.led.length).fill({});// Array of black LEDs everloop[0] = {b:100}; setInterval(()=>{ let lastColor = everloop.shift(); everloop.push(lastColor); matrix.led.set(everloop); },50);
const matrix = require("@matrix-io/matrix-lite"); let everloop = new Array(matrix.led.length); let ledAdjust = 0.0; if (everloop.length == 35) { ledAdjust = 0.51; // MATRIX Creator } else { ledAdjust = 1.01; // MATRIX Voice } let frequency = 0.375; let counter = 0.0; let tick = everloop.length - 1; setInterval(()=>{ // Create rainbow for(i = 0; i < everloop.length; i++) { let led = {}; led.r = Math.round(Math.max(0, (Math.sin(frequency*counter+(Math.PI/180*240))*155+100)/10)); led.g = Math.round(Math.max(0, (Math.sin(frequency*counter+(Math.PI/180*120))*155+100)/10)); led.b = Math.round(Math.max(0, (Math.sin(frequency*counter)*155+100)/10)); counter += ledAdjust; everloop[i] = led; }; // Slowly show rainbow if (tick != 0) { for (i = tick; i > 0; i--) { everloop[i] = {}; } tick--; } matrix.led.set(everloop); },35);