API Docs for: 1.1.1
Show:

BlinkStick Class

Initialize new BlinkStick device

Constructor

BlinkStick

(
  • device
  • [serialNumber]
  • [manufacturer]
  • [product]
)

Parameters:

  • device Object

    The USB device as returned from "usb" package.

  • [serialNumber] String optional

    Serial number of the device. Used only in Windows.

  • [manufacturer] String optional

    Manufacturer of the device. Used only in Windows.

  • [product] String optional

    Product name of the device. Used only in Windows.

Methods

_determineReportId

() Object private

Determines report ID and number of LEDs for the report

Returns:

Object:

data.reportId and data.ledCount

close

()

Close BlinkStick device and stop all animations

decimalToHex

(
  • d
  • padding
)
String private

Converts decimal number to hex with zero padding

Parameters:

  • d Number

    Decimal number to convert

  • padding Number

    How many zeros to use for padding

Returns:

String:

Decimal number converted to hex string

findBlinkSticks

(
  • [filter]
)
Array

Find BlinkSticks using a filter.

Parameters:

  • [filter] Function optional

    Filter function.

Returns:

Array:

BlickStick objects.

getColor

(
  • index
  • callback
)
Number, Number, Number

Get the current color visible on BlinkStick

Function supports the following overloads:

Parameters:

  • index Number=0

    The index of the LED

  • callback Function

    Callback to which to pass the color values.

Returns:

Number, Number, Number:

Callback returns three numbers: R, G and B [0..255].

Example:

//Available overloads
getColor(callback); //index defaults to 0

getColor(index, callback);
getColor(0, function(err, r, g, b) {
    console.log(r, g, b);
});

getColors

(
  • count
  • callback
)
Array

Get the current color frame on BlinkStick Pro

Usage:

Parameters:

  • count Number

    How many LEDs should return

  • callback Function

    Callback to which to pass the color values.

Returns:

Array:

Callback returns an array of LED data in the following format: [g0, r0, b0, g1, r1, b1...]

Example:

getColors(8, function(err, data) {
    console.log(data);
});

getColorString

(
  • index
  • callback
)
String

Get the current color as hex string.

Function supports the following overloads:

Parameters:

  • index Number

    The index of the LED to retrieve data

  • callback Function

    Callback to which to pass the color string.

Returns:

String:

Hex string, eg "#BADA55".

Example:

//Available overloads
getColorString(callback); //index defaults to 0

getColorString(index, callback);
getColorString(0, function(err, color) {
    console.log(color);
});

getColorString(function(err, color) {
    console.log(color);
});

getDescription

(
  • callback
)

Get the description of the device

Usage:

Parameters:

  • callback Function

    Callback to receive description

Example:

getDescription(function(err, data) {
    console.log(data);
});

getFeatureReport

(
  • reportId
  • length
  • callback
)

Get feature report from the device.

Parameters:

  • reportId Number

    Report ID to receive

  • length Number

    Expected length of the report

  • callback Function

    Function called when report received

getInfoBlock

(
  • device
  • location
  • callback
)
private static

Get an infoblock from a device.

Parameters:

  • device BlinkStick

    Device from which to get the value.

  • location Number

    Address to seek the data.

  • callback Function

    Callback to which to pass the value.

getInfoBlock1

(
  • callback
)

Get the infoblock1 of the device. This is a 32 byte array that can contain any data. It's supposed to hold the "Name" of the device making it easier to identify rather than a serial number.

Usage:

Parameters:

  • callback Function

    Callback to which to pass the value.

Example:

getInfoBlock1(function(err, data) {
    console.log(data);
});

getInfoBlock2

(
  • callback
)

Get the infoblock2 of the device. This is a 32 byte array that can contain any data.

Usage:

Parameters:

  • callback Function

    Callback to which to pass the value.

Example:

getInfoBlock2(function(err, data) {
    console.log(data);
});

getInverse

() Boolean

Get inverse mode setting for IKEA DIODER in conjunction with BlinkStick v1.0

Returns:

Boolean:

true for enabled inverse mode and false otherwise

getManufacturer

(
  • callback
)

Get the manufacturer of the device

Usage:

Parameters:

  • callback Function

    Callback to receive manufacturer name

Example:

getManufacturer(function(err, data) {
    console.log(data);
});

getMode

(
  • callback
)

Get mode for BlinkStick Pro

  • 0 = Normal
  • 1 = Inverse
  • 2 = WS2812

You can read more about BlinkStick modes by following this link:

http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes

Usage:

Parameters:

  • callback Callback

    receive mode with callback

Example:

getMode(function(err, data) {
    console.log(data);
});

getSerial

(
  • callback
)

Returns the serial number of device.

BSnnnnnn-1.0
||  |    | |- Software minor version
||  |    |--- Software major version
||  |-------- Denotes sequential number
||----------- Denotes BlinkStick device

Software version defines the capabilities of the device

Usage:

Parameters:

  • callback Function

    Callback to receive serial number

Example:

getSerial(function(err, serial) {
    console.log(serial);
});

getVersionMajor

() Number

Get the major version from serial number

Returns:

Number:

Major version number from serial

getVersionMinor

() Number

Get the minor version from serial number

Returns:

Number:

Minor version number from serial

interpretParameters

(
  • red
  • [green]
  • [blue]
  • [options]
  • [callback]
)
Object private

Automatically interpret parameters supplied for functions to generate overrides.

Parameters:

  • red Number | String

    Red color intensity 0 is off, 255 is full red intensity OR string CSS color keyword OR hex color, eg "#BADA55".

  • [green] Number optional

    Green color intensity 0 is off, 255 is full green intensity.

  • [blue] Number optional

    Blue color intensity 0 is off, 255 is full blue intensity.

  • [options] Object optional

    additional options

  • [callback] Function optional

    Callback, called when complete.

Returns:

Object:

Conains sanitized RGB value, options and callback if they have been assigned

morph

(
  • red
  • [green]
  • [blue]
  • [options]
  • [callback]
)

Morphs to specified RGB color from current color.

Function supports the following overloads:

Parameters:

  • red Number | String

    Red color intensity 0 is off, 255 is full red intensity OR string CSS color keyword OR hex color, eg "#BADA55".

  • [green] Number optional

    Green color intensity 0 is off, 255 is full green intensity.

  • [blue] Number optional

    Blue color intensity 0 is off, 255 is full blue intensity.

  • [options] Object optional

    additional options {"channel": 0, "index": 0, "duration": 1000, "steps": 50}

  • [callback] Function optional

    Callback when the operation completes

Example:

//Available overloads
morph(red, green, blue, [options], [callback]); // use [0..255] ranges for intensity

morph(color, [options], [callback]); // use '#rrggbb' format

morph(color_name, [options], [callback]); // use 'random', 'red', 'green', 'yellow' and other CSS supported names

Options can contain the following parameters for object:

  • channel=0: Channel is represented as 0=R, 1=G, 2=B
  • index=0: The index of the LED
  • duration=1000: How long should the morph animation last in milliseconds
  • steps=50: How many steps for color changes

opt

(
  • options
  • name
  • defaultValue
)
private static

Get default value from options

Parameters:

  • options Object

    Option object to operate on

  • name String

    The name of the parameter

  • defaultValue Object

    Default value if name is not found in option object

pulse

(
  • red
  • [green]
  • [blue]
  • [options]
  • [callback]
)

Pulses specified RGB color.

Function supports the following overloads:

Parameters:

  • red Number | String

    Red color intensity 0 is off, 255 is full red intensity OR string CSS color keyword OR hex color, eg "#BADA55".

  • [green] Number optional

    Green color intensity 0 is off, 255 is full green intensity.

  • [blue] Number optional

    Blue color intensity 0 is off, 255 is full blue intensity.

  • [options] Object optional

    additional options {"channel": 0, "index": 0, "duration": 1000, "steps": 50}

  • [callback] Function optional

    Callback when the operation completes

Example:

//Available overloads
pulse(red, green, blue, [options], [callback]); // use [0..255] ranges for intensity

pulse(color, [options], [callback]); // use '#rrggbb' format

pulse(color_name, [options], [callback]); // use 'random', 'red', 'green', 'yellow' and other CSS supported names

Options can contain the following parameters for object:

  • channel=0: Channel is represented as 0=R, 1=G, 2=B
  • index=0: The index of the LED
  • duration=1000: How long should the pulse animation last in milliseconds
  • steps=50: How many steps for color changes

randomIntInc

(
  • low
  • high
)
Number private static

Generate random integer number within a range.

Parameters:

  • low Number

    the low value of the number

  • high Number

    the high value of the number

Returns:

Number:

Random number in the range of [low..high] inclusive of low and high

setColor

(
  • red
  • [green]
  • [blue]
  • [options]
  • [callback]
)

Set the color of LEDs

Parameters:

  • red Number | String

    Red color intensity 0 is off, 255 is full red intensity OR string CSS color keyword OR hex color, eg "#BADA55".

  • [green] Number optional

    Green color intensity 0 is off, 255 is full green intensity.

  • [blue] Number optional

    Blue color intensity 0 is off, 255 is full blue intensity.

  • [options] Object optional

    additional options {"channel": 0, "index": 0}. Channel is represented as 0=R, 1=G, 2=B

  • [callback] Function optional

    Callback, called when complete.

Example:

//Available overloads
setColor(red, green, blue, [options], [callback]); // use [0..255] ranges for intensity

setColor(color, [options], [callback]); // use '#rrggbb' format

setColor(color_name, [options], [callback]); // use 'random', 'red', 'green', 'yellow' and other CSS supported names

setColors

(
  • channel
  • data
  • callback
)

Set the color frame on BlinkStick Pro

Parameters:

  • channel Number

    Channel is represented as 0=R, 1=G, 2=B

  • data Array

    LED data in the following format: [g0, r0, b0, g1, r1, b1...]

  • callback Function

    Callback when the operation completes

Example:

var data = [255, 0, 0, 0, 255, 0];

setColors(0, data, function(err) {
});

setFeatureReport

(
  • reportId
  • data
  • callback
)

Set feature report to the device.

Parameters:

  • reportId Number

    Report ID to receive

  • data Array

    Data to send to the device

  • callback Function

    Function called when report sent

setInfoBlock

(
  • device
  • location
  • data
  • callback
)
private static

Sets an infoblock on a device.

Parameters:

  • device BlinkStick

    Device on which to set the value.

  • location Number

    Address to seek the data.

  • data String

    The value to push to the device. Should be <= 32 chars.

  • callback Function

    Callback to which to pass the value.

setInfoBlock1

(
  • data
  • callback
)

Sets the infoblock1 with specified string. It fills the rest of bytes with zeros.

Usage:

Parameters:

  • data String

    Data value for InfoBlock

  • callback Function

    Callback when the operation completes

Example:

setInfoBlock1("abcdefg", function(err) {
});

setInfoBlock2

(
  • data
  • callback
)

Sets the infoblock2 with specified string. It fills the rest of bytes with zeros.

Usage:

Parameters:

  • data String

    Data value for InfoBlock

  • callback Function

    Callback when the operation completes

Example:

setInfoBlock2("abcdefg", function(err) {
});

setInverse

(
  • inverse
)

Set inverse mode for IKEA DIODER in conjunction with BlinkStick v1.0

Parameters:

  • inverse Boolean

    Set true for inverse mode and false otherwise

setMode

(
  • mode
)

Set mode for BlinkStick Pro

  • 0 = Normal
  • 1 = Inverse
  • 2 = WS2812

You can read more about BlinkStick modes by following this link:

http://www.blinkstick.com/help/tutorials/blinkstick-pro-modes

Parameters:

  • mode Number

    Set the desired mode for BlinkStick Pro

setRandomColor

()

Sets the LED to a random color.

stop

()

Stop all animations

turnOff

()

Turns the LED off.