2.0.0-close-7defed21ef36af34caf70c570a982b8fdd226958 • Published 6 years ago
sys-class-rgb-led v2.0.0-close-7defed21ef36af34caf70c570a982b8fdd226958
sys-class-rgb-led
Animates /sys/class/leds rgb leds
Example
For controlling an RGB led using /sys/class/leds/pca963x:{red,green,blue}/brightness files:
import { RGBLed, breatheGreen, blinkWhite } from 'sys-class-rgb-led';
const led = new RGBLed([
'pca963x:red',
'pca963x:green',
'pca963x:blue',
]);
await led.setStaticColor([0.5, 0.5, 0.5]);
// or
await led.setAnimation(breatheGreen);
// or
await led.setAnimation(blinkWhite);
await led.setStaticColor([0, 0, 0]);
await led.close();A Color is an Array of 3 numbers between 0 and 1.
An AnimationFunction is a function that takes a timestamp in milliseconds as parameter and returns a Color.
setAnimation accepts a second optional frequency parameter, the default value is 10Hz.
setAnimation returns a Promise that will resolve when the first color of the animation has been set.
setStaticColor returns a Promise that will resolve when the color has been set.
This might be useful if you want to be sure that the color has been set before calling close().