blinkt-kit

2.2.1 • Public • Published

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.

Parameters
pixel Number (optional)
The Pixel to update 0 to 7
Defaults to 0
r Number (optional)
The RED value for the Pixel 0 to 255
Defaults to 0
g Number (optional)
The GREEN value for the Pixel 0 to 255
Defaults to 0
b Number (optional)
The BLUE value for the Pixel 0 to 255
Defaults to 0
brightness Number (optional)
The relative brightness for the pixel 0.0 to 1.0
Defaults to 0.2
setAll({ r, g, b, brightness })

Set all of the Blinkt! pixels to the same values.

Parameters
r Number (optional)
The RED value for the Pixel 0 to 255
Defaults to 0
g Number (optional)
The GREEN value for the Pixel 0 to 255
Defaults to 0
b Number (optional)
The BLUE value for the Pixel 0 to 255
Defaults to 0
brightness Number (optional)
The relative brightness for the pixel 0.0 to 1.0
Defaults to 0.2
getAll()

Return the current state of the Blinkt! pixels.

flashPixel({pixel, times, intervalms, r, g, b, brightness})
Parameters
pixel Number (optional)
The Pixel to update 0 to 7
Defaults to 0
times Number (optional)
The number of times to flash the pixel
Defaults to 0
intervalms Number (optional)
The milliseconds to pause between state changes
Defaults to 0
r Number (optional)
The RED value for the Pixel 0 to 255
Defaults to 0
g Number (optional)
The GREEN value for the Pixel 0 to 255
Defaults to 0
b Number (optional)
The BLUE value for the Pixel 0 to 255
Defaults to 0
brightness Number (optional)
The relative brightness for the pixel 0.0 to 1.0
Defaults to 0.2
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.

Parameters
pixel Number (optional)
The pixel number 0 to 7
brightness Number (optional)
The relative brightness for the pixel 0.0 to 1.0
Defaults to 0.2
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.

Parameters
r Number (optional)
The RED value for the Pixel 0 to 255
Defaults to 0
g Number (optional)
The GREEN value for the Pixel 0 to 255
Defaults to 0
b Number (optional)
The BLUE value for the Pixel 0 to 255
Defaults to 0
showFinalAnimation({r, g, b})
Parameters
r Number (optional)
The RED value for the Pixel 0 to 255
Defaults to 0
g Number (optional)
The GREEN value for the Pixel 0 to 255
Defaults to 0
b Number (optional)
The BLUE value for the Pixel 0 to 255
Defaults to 0
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.

Parameters
shouldClearOnExit Boolean Default: true

Importantly!

show()

Commits all the 'set' operations to the Blinkt! (Nothing will show without this!)

Acknowledgements

Package Sidebar

Install

npm i blinkt-kit

Weekly Downloads

3

Version

2.2.1

License

MIT

Unpacked Size

24.5 kB

Total Files

9

Last publish

Collaborators

  • chriskinsman
  • globalroo