BlinkStick Class
Initialize new BlinkStick device
Constructor
BlinkStick
-
device
-
[serialNumber]
-
[manufacturer]
-
[product]
Parameters:
-
device
ObjectThe USB device as returned from "usb" package.
-
[serialNumber]
String optionalSerial number of the device. Used only in Windows.
-
[manufacturer]
String optionalManufacturer of the device. Used only in Windows.
-
[product]
String optionalProduct name of the device. Used only in Windows.
Item Index
Methods
- _determineReportId
- blink
- close
- decimalToHex
- findBlinkSticks
- getColor
- getColors
- getColorString
- getDescription
- getFeatureReport
- getInfoBlock static
- getInfoBlock1
- getInfoBlock2
- getInverse
- getManufacturer
- getMode
- getSerial
- getVersionMajor
- getVersionMinor
- interpretParameters
- morph
- opt static
- pulse
- randomIntInc static
- setColor
- setColors
- setFeatureReport
- setInfoBlock static
- setInfoBlock1
- setInfoBlock2
- setInverse
- setMode
- setRandomColor
- stop
- turnOff
Methods
_determineReportId
()
Object
private
Determines report ID and number of LEDs for the report
Returns:
data.reportId and data.ledCount
blink
-
red
-
[green]
-
[blue]
-
[options]
-
[callback]
Blinks specified RGB color.
Function supports the following overloads:
Parameters:
-
red
Number | StringRed color intensity 0 is off, 255 is full red intensity OR string CSS color keyword OR hex color, eg "#BADA55".
-
[green]
Number optionalGreen color intensity 0 is off, 255 is full green intensity.
-
[blue]
Number optionalBlue color intensity 0 is off, 255 is full blue intensity.
-
[options]
Object optionaladditional options {"channel": 0, "index": 0, "repeats": 1, "delay": 500}
-
[callback]
Function optionalCallback when the operation completes
Example:
//Available overloads
blink(red, green, blue, [options], [callback]); // use [0..255] ranges for intensity
blink(color, [options], [callback]); // use '#rrggbb' format
blink(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
- repeats=1: How many times to blink
- delay=1: Delay between on/off cycles in milliseconds
close
()
Close BlinkStick device and stop all animations
decimalToHex
-
d
-
padding
Converts decimal number to hex with zero padding
Parameters:
-
d
NumberDecimal number to convert
-
padding
NumberHow many zeros to use for padding
Returns:
Decimal number converted to hex string
findBlinkSticks
-
[filter]
Find BlinkSticks using a filter.
Parameters:
-
[filter]
Function optionalFilter function.
Returns:
BlickStick objects.
getColor
-
index
-
callback
Get the current color visible on BlinkStick
Function supports the following overloads:
Parameters:
-
index
Number=0The index of the LED
-
callback
FunctionCallback to which to pass the color values.
Returns:
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
Get the current color frame on BlinkStick Pro
Usage:
Parameters:
-
count
NumberHow many LEDs should return
-
callback
FunctionCallback to which to pass the color values.
Returns:
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
Get the current color as hex string.
Function supports the following overloads:
Parameters:
-
index
NumberThe index of the LED to retrieve data
-
callback
FunctionCallback to which to pass the color string.
Returns:
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
FunctionCallback to receive description
Example:
getDescription(function(err, data) {
console.log(data);
});
getFeatureReport
-
reportId
-
length
-
callback
Get feature report from the device.
Parameters:
-
reportId
NumberReport ID to receive
-
length
NumberExpected length of the report
-
callback
FunctionFunction called when report received
getInfoBlock
-
device
-
location
-
callback
Get an infoblock from a device.
Parameters:
-
device
BlinkStickDevice from which to get the value.
-
location
NumberAddress to seek the data.
-
callback
FunctionCallback 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
FunctionCallback 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
FunctionCallback 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:
true for enabled inverse mode and false otherwise
getManufacturer
-
callback
Get the manufacturer of the device
Usage:
Parameters:
-
callback
FunctionCallback 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
Callbackreceive 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
FunctionCallback to receive serial number
Example:
getSerial(function(err, serial) {
console.log(serial);
});
getVersionMajor
()
Number
Get the major version from serial number
Returns:
Major version number from serial
getVersionMinor
()
Number
Get the minor version from serial number
Returns:
Minor version number from serial
interpretParameters
-
red
-
[green]
-
[blue]
-
[options]
-
[callback]
Automatically interpret parameters supplied for functions to generate overrides.
Parameters:
-
red
Number | StringRed color intensity 0 is off, 255 is full red intensity OR string CSS color keyword OR hex color, eg "#BADA55".
-
[green]
Number optionalGreen color intensity 0 is off, 255 is full green intensity.
-
[blue]
Number optionalBlue color intensity 0 is off, 255 is full blue intensity.
-
[options]
Object optionaladditional options
-
[callback]
Function optionalCallback, called when complete.
Returns:
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 | StringRed color intensity 0 is off, 255 is full red intensity OR string CSS color keyword OR hex color, eg "#BADA55".
-
[green]
Number optionalGreen color intensity 0 is off, 255 is full green intensity.
-
[blue]
Number optionalBlue color intensity 0 is off, 255 is full blue intensity.
-
[options]
Object optionaladditional options {"channel": 0, "index": 0, "duration": 1000, "steps": 50}
-
[callback]
Function optionalCallback 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
Get default value from options
Parameters:
-
options
ObjectOption object to operate on
-
name
StringThe name of the parameter
-
defaultValue
ObjectDefault 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 | StringRed color intensity 0 is off, 255 is full red intensity OR string CSS color keyword OR hex color, eg "#BADA55".
-
[green]
Number optionalGreen color intensity 0 is off, 255 is full green intensity.
-
[blue]
Number optionalBlue color intensity 0 is off, 255 is full blue intensity.
-
[options]
Object optionaladditional options {"channel": 0, "index": 0, "duration": 1000, "steps": 50}
-
[callback]
Function optionalCallback 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
Generate random integer number within a range.
Parameters:
-
low
Numberthe low value of the number
-
high
Numberthe high value of the number
Returns:
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 | StringRed color intensity 0 is off, 255 is full red intensity OR string CSS color keyword OR hex color, eg "#BADA55".
-
[green]
Number optionalGreen color intensity 0 is off, 255 is full green intensity.
-
[blue]
Number optionalBlue color intensity 0 is off, 255 is full blue intensity.
-
[options]
Object optionaladditional options {"channel": 0, "index": 0}. Channel is represented as 0=R, 1=G, 2=B
-
[callback]
Function optionalCallback, 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
NumberChannel is represented as 0=R, 1=G, 2=B
-
data
ArrayLED data in the following format: [g0, r0, b0, g1, r1, b1...]
-
callback
FunctionCallback 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
NumberReport ID to receive
-
data
ArrayData to send to the device
-
callback
FunctionFunction called when report sent
setInfoBlock
-
device
-
location
-
data
-
callback
Sets an infoblock on a device.
Parameters:
-
device
BlinkStickDevice on which to set the value.
-
location
NumberAddress to seek the data.
-
data
StringThe value to push to the device. Should be <= 32 chars.
-
callback
FunctionCallback 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
StringData value for InfoBlock
-
callback
FunctionCallback 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
StringData value for InfoBlock
-
callback
FunctionCallback 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
BooleanSet 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
NumberSet the desired mode for BlinkStick Pro
setRandomColor
()
Sets the LED to a random color.
stop
()
Stop all animations
turnOff
()
Turns the LED off.