Package blinkstick :: Module blinkstick :: Class BlinkStick
[frames] | no frames]

Class BlinkStick

source code

object --+
         |
        BlinkStick

BlinkStick class is designed to control regular BlinkStick devices, or BlinkStick Pro devices in Normal or Inverse modes. Please refer to BlinkStick.set_mode for more details about BlinkStick Pro device modes.

Code examples on how you can use this class are available here:

https://github.com/arvydas/blinkstick-python/wiki

Instance Methods
 
__init__(self, device=None, error_reporting=True)
Constructor for the class.
source code
str
get_serial(self)
Returns the serial number of device.:
source code
str
get_manufacturer(self)
Get the manufacturer of the device
source code
str
get_description(self)
Get the description of the device
source code
 
set_error_reporting(self, error_reporting)
Enable or disable error reporting
source code
 
set_color(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None)
Set the color to the device as RGB
source code
(int, int, int) or str
get_color(self, index=0, color_format='rgb')
Get the current device color in the defined format.
source code
 
set_led_data(self, channel, data)
Send LED data frame.
source code
int[0..64*3]
get_led_data(self, count)
Get LED data frame on the device.
source code
 
set_mode(self, mode)
Set device mode for BlinkStick Pro.
source code
int
get_mode(self)
Get BlinkStick Pro mode.
source code
str
get_info_block1(self)
Get the infoblock1 of the device.
source code
str
get_info_block2(self)
Get the infoblock2 of the device.
source code
 
set_info_block1(self, data)
Sets the infoblock1 with specified string.
source code
 
set_info_block2(self, data)
Sets the infoblock2 with specified string.
source code
 
set_random_color(self)
Sets random color to the device.
source code
 
turn_off(self)
Turns off LED.
source code
 
pulse(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None, repeats=1, duration=1000, steps=50)
Morph to the specified color from black and back again.
source code
 
blink(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None, repeats=1, delay=500)
Blink the specified color.
source code
 
morph(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None, duration=1000, steps=50)
Morph to the specified color.
source code
 
open_device(self, d)
Open device.
source code
bool
get_inverse(self)
Get the value of inverse mode.
source code
 
set_inverse(self, value)
Set inverse mode.
source code
 
set_max_rgb_value(self, value)
Set RGB color limit.
source code
int
get_max_rgb_value(self, max_rgb_value)
Get RGB color limit.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables
  HEX_COLOR_RE = re.compile(r'^#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})$')
  inverse = False
  error_reporting = True
  max_rgb_value = 255
Properties

Inherited from object: __class__

Method Details

__init__(self, device=None, error_reporting=True)
(Constructor)

source code 

Constructor for the class.

Parameters:
  • error_reporting (Boolean) - display errors if they occur during communication with the device
Overrides: object.__init__

get_serial(self)

source code 

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

Returns: str
Serial number of the device

get_manufacturer(self)

source code 

Get the manufacturer of the device

Returns: str
Device manufacturer's name

get_description(self)

source code 

Get the description of the device

Returns: str
Device description

set_error_reporting(self, error_reporting)

source code 

Enable or disable error reporting

Parameters:
  • error_reporting (Boolean) - display errors if they occur during communication with the device

set_color(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None)

source code 

Set the color to the device as RGB

Parameters:
  • red (int) - Red color intensity 0 is off, 255 is full red intensity
  • green (int) - Green color intensity 0 is off, 255 is full green intensity
  • blue (int) - Blue color intensity 0 is off, 255 is full blue intensity
  • name (str) - Use CSS color name as defined here: http://www.w3.org/TR/css3-color/
  • hex (str) - Specify color using hexadecimal color value e.g. '#FF3366'

get_color(self, index=0, color_format='rgb')

source code 

Get the current device color in the defined format.

Currently supported formats:

  1. rgb (default) - Returns values as 3-tuple (r,g,b)
  2. hex - returns current device color as hexadecimal string
    >>> b = blinkstick.find_first()
    >>> b.set_color(red=255,green=0,blue=0)
    >>> (r,g,b) = b.get_color() # Get color as rbg tuple
    (255,0,0)
    >>> hex = b.get_color(color_format='hex') # Get color as hex string 
    '#ff0000'
Parameters:
  • index (int) - the index of the LED
  • color_format (str) - "rgb" or "hex". Defaults to "rgb".
Returns: (int, int, int) or str
Either 3-tuple for R, G and B values, or hex string

set_led_data(self, channel, data)

source code 

Send LED data frame.

Parameters:
  • channel (int) - the channel which to send data to (R=0, G=1, B=2)
  • data (int[0..64*3]) - The LED data frame in GRB format

get_led_data(self, count)

source code 

Get LED data frame on the device.

Parameters:
  • count (int) - How much data to retrieve. Can be in the range of 0..64*3
Returns: int[0..64*3]
LED data currently stored in the RAM of the device

set_mode(self, mode)

source code 

Set device mode for BlinkStick Pro. Device currently supports the following modes:

  • 0 - (default) use R, G and B channels to control single RGB LED
  • 1 - same as 0, but inverse mode
  • 2 - control up to 64 WS2812 individual LEDs per each R, G and B channel

You can find out more about BlinkStick Pro modes:

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

Parameters:
  • mode (int) - Device mode to set

get_mode(self)

source code 

Get BlinkStick Pro mode. Device currently supports the following modes:

  • 0 - (default) use R, G and B channels to control single RGB LED
  • 1 - same as 0, but inverse mode
  • 2 - control up to 64 WS2812 individual LEDs per each R, G and B channel

You can find out more about BlinkStick Pro modes:

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

Returns: int
Device mode

get_info_block1(self)

source code 

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.

Returns: str
InfoBlock1 currently stored on the device

get_info_block2(self)

source code 

Get the infoblock2 of the device.

This is a 32 byte array that can contain any data.

Returns: str
InfoBlock2 currently stored on the device

set_info_block1(self, data)

source code 

Sets the infoblock1 with specified string.

It fills the rest of 32 bytes with zeros.

Parameters:
  • data (str) - InfoBlock1 for the device to set

set_info_block2(self, data)

source code 

Sets the infoblock2 with specified string.

It fills the rest of 32 bytes with zeros.

Parameters:
  • data (str) - InfoBlock2 for the device to set

pulse(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None, repeats=1, duration=1000, steps=50)

source code 

Morph to the specified color from black and back again.

Parameters:
  • red (int) - Red color intensity 0 is off, 255 is full red intensity
  • green (int) - Green color intensity 0 is off, 255 is full green intensity
  • blue (int) - Blue color intensity 0 is off, 255 is full blue intensity
  • name (str) - Use CSS color name as defined here: http://www.w3.org/TR/css3-color/
  • hex (str) - Specify color using hexadecimal color value e.g. '#FF3366'
  • repeats (int) - Number of times to pulse the LED
  • duration (int) - Duration for pulse in milliseconds
  • steps (int) - Number of gradient steps

blink(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None, repeats=1, delay=500)

source code 

Blink the specified color.

Parameters:
  • red (int) - Red color intensity 0 is off, 255 is full red intensity
  • green (int) - Green color intensity 0 is off, 255 is full green intensity
  • blue (int) - Blue color intensity 0 is off, 255 is full blue intensity
  • name (str) - Use CSS color name as defined here: http://www.w3.org/TR/css3-color/
  • hex (str) - Specify color using hexadecimal color value e.g. '#FF3366'
  • repeats (int) - Number of times to pulse the LED
  • delay (int) - time in milliseconds to light LED for, and also between blinks

morph(self, channel=0, index=0, red=0, green=0, blue=0, name=None, hex=None, duration=1000, steps=50)

source code 

Morph to the specified color.

Parameters:
  • red (int) - Red color intensity 0 is off, 255 is full red intensity
  • green (int) - Green color intensity 0 is off, 255 is full green intensity
  • blue (int) - Blue color intensity 0 is off, 255 is full blue intensity
  • name (str) - Use CSS color name as defined here: http://www.w3.org/TR/css3-color/
  • hex (str) - Specify color using hexadecimal color value e.g. '#FF3366'
  • duration (int) - Duration for morph in milliseconds
  • steps (int) - Number of gradient steps (default 50)

open_device(self, d)

source code 

Open device.

Parameters:
  • d - Device to open

get_inverse(self)

source code 

Get the value of inverse mode. This applies only to BlinkStick. Please use set_mode for BlinkStick Pro to permanently set the inverse mode to the device.

Returns: bool
True if inverse mode, otherwise false

set_inverse(self, value)

source code 

Set inverse mode. This applies only to BlinkStick. Please use set_mode for BlinkStick Pro to permanently set the inverse mode to the device.

Parameters:
  • value (bool) - True/False to set the inverse mode

set_max_rgb_value(self, value)

source code 

Set RGB color limit. {set_color} function will automatically remap the values to maximum supplied.

Parameters:
  • value (int) - 0..255 maximum value for each R, G and B color

get_max_rgb_value(self, max_rgb_value)

source code 

Get RGB color limit. {set_color} function will automatically remap the values to maximum set.

Returns: int
0..255 maximum value for each R, G and B color