blinkt-kit
v2.2.1
Published
Pimoroni Blinkt! NodeJS bindings. Based on node-blinkt. Updated for Node > 8.
Downloads
43
Readme
blinkt-kit
Pimoroni Blinkt! NodeJS bindings. Based on node-blinkt. Updated for Node > 8.
npm install blinkt-kit --save
Basic example
const { Blinkt } = require("blinkt-kit");
const blinkt = new Blinkt();
blinkt.setAll({ r: 128, g: 0, b: 128, brightness: 0.2 });
blinkt.setPixel({ pixel: 0, r: 255 });
blinkt.setPixel({ pixel: 1, g: 255 });
blinkt.setPixel({ pixel: 2, b: 255 });
// Send update applies your changes to the Blinkt!
blinkt.show();
// Switch everything off after two seconds.
setTimeout(() => {
blinkt.clear();
}, 2000);
Other examples
const { Blinkt, COLOURS, PI_RAINBOW } = require("blinkt-kit");
const blinkt = new Blinkt({ clearOnExit: true });
const TEST_DELAY = 1000;
const showInitialAnimation = colour =>
new Promise(resolve => {
blinkt.showInitialAnimation({ ...colour });
setTimeout(() => resolve(), TEST_DELAY);
})
const showFinalAnimation = colour =>
new Promise(resolve => {
blinkt.showFinalAnimation({ ...colour });
setTimeout(() => resolve(), TEST_DELAY);
})
const flashPixel = (ix, colour) =>
new Promise(resolve => {
blinkt.flashPixel({ pixel: ix, times: 2, intervalms: 500, brightness: 0.5, ...colour });
setTimeout(() => resolve(), TEST_DELAY);
})
const turnAllOnWithColour = colour =>
new Promise(resolve => {
blinkt.setAll({ ...colour });
blinkt.show();
setTimeout(() => resolve(), TEST_DELAY);
});
const turnOnWithColour = (ix, colour) =>
new Promise(resolve => {
blinkt.setPixel({ pixel: ix, ...colour });
blinkt.show();
setTimeout(() => resolve(), TEST_DELAY);
});
const runThrough = async () => {
await showInitialAnimation(COLOURS.GREEN);
await flashPixel(2, COLOURS.GREEN);
await turnAllOnWithColour(COLOURS.RED);
await turnAllOnWithColour(COLOURS.GREEN);
await turnAllOnWithColour(COLOURS.BLUE);
await showFinalAnimation(COLOURS.RED);
};
const basicColours = async () => {
for (let ix = 0, length = PI_RAINBOW.length; ix < length; ix++) {
await turnOnWithColour(ix, PI_RAINBOW[ix]);
}
};
runThrough().then(async () => {
await setTimeout(() => basicColours(), TEST_DELAY);
});
API
setPixel({ pixel = 0, r, g, b, brightness = DEFAULT_BRIGHTNESS })
Set an individual Blinkt! pixel to the a specific value.
setAll({ r, g, b, brightness })
Set all of the Blinkt! pixels to the same values.
getAll()
Return the current state of the Blinkt! pixels.
flashPixel({pixel, times, intervalms, r, g, b, brightness})
setBrightness({ pixel, brightness = DEFAULT_BRIGHTNESS })
Set the brightness of all the Blinkt! pixels if no pixel specified, or the brightness for all of them if no PixelNumber specified.
showInitialAnimation({r, g, b})
Show an animation that starts with two pixels in the center fading up, extends outwards at full brightness and then turns off.
showFinalAnimation({r, g, b})
clear()
Unsets all of the Blinkt! Pixels
setClearOnExit(true|false)
Will undo all Blinkt! configuration and reset LEDs if the process ends or is interrupted with CTRL C.
Importantly!
show()
Commits all the 'set' operations to the Blinkt! (Nothing will show without this!)
Acknowledgements
Original python code: http://docs.pimoroni.com/blinkt/
Updated to use rpio for Node 12+ compatibility by Chris Kinsman