The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Device::BlinkStick::Stick

SYNOPSIS

    use 5.10.0 ;
    use strict ;
    use warnings ;
    use Device::BlinkStick;

    my $bs = Device::BlinkStick->new() ;
    # get the first blinkstick found
    my $device = $bs->first() ;
    # make it red
    $first->led( color => 'red') ;

    sleep( 2) ;
    # blink red for 5 times, delaying for 250ms between black and the color
    $first->blink( color => 'red', delay => 250, times => 5) ;    

DESCRIPTION

Object holding information and control about a specic blinkstick device, the control of a single device is done in Device::BlinkStick::Stick

new

Create an instance of a blink stick device, requires an open USB file device

verbose

output some debug as things happen

serial_number

optionally find this stick

device_name

optionally find this stick, if serial_number is also defined that will over-ride I am working on the premise that the device name is stored in info_block_1

info

get a hash of info about the device

get_device_name

get the contents of info_block_1, usually the device name?

get_access_token

get the contents of get_info_block_2, maybe the acccess token for the online service? unused for perl

set_device_name

str

string to write into info_block_1, the device name

This will get trimmed to 32 characters

    $stick->set_device_name( 'strip') ;

returns true/false depending if the string was set

set_access_token

str

string to write into info_block_2, the online access token. Not used by perl

This will get trimmed to 32 characters

    $stick->set_access_token( 'abc123dead') ;

returns true/false depending if the string was set

get_mode

returns the display mode

0 normal 1 inverse 2 WS2812 3 WS2812 mirror - all leds the same

    my $mode =  $stick->get_mode() ;

set_mode

Set the display mode

mode

mode to set

  0 normal 
  1 inverse
  2 WS2812
  3 WS2812 mirror - all leds the same

    $stick->set_mode( 3) ;

returns true/false depending if the mode was set

get_color

returns the color as rgb from a channel and index

    my $c = $stick->get_color( 0, 0 ) ;

set_color

set the rgb color for a single pixel blinkstick, uses brightness

Parameters

r

red part 0..255

g

green part 0..255

b

blue part 0..255

channel

64 LED block to use

index

LED in block to use

    $stick->set_color( 255, 0, 255, 0, 0) ;

This should not be used directly, rather use the led method instead

returns true/false depending if the mode was set

led

set the color of a single pixel blinkstick, uses brightness

Parameters

color

Color is either a colorname from WebColors or a hex triplet of the form FF00AA

channel

64 LED block to use

index

LED in block to use

    $stick->led( color => 'green200', index => 0, channel => 0) ;
   

returns true/false depending if the mode was set

blink a single pixel on and off, uses brightness

Parameters

color

Color is either a colorname from WebColors or a hex triplet FF00AA

channel

64 LED block to use

index

LED in block to use

times

Number of times to blink on and off

delay

Pause period between blinks, defaults to DEFAULT_BLINK_TIME which is 150ms

    $stick->blink( color => 'green200', index => 0, channel => 0, times => 5) ;

get_leds

returns the number of leds on the device

set_leds

set the number of leds connected to a device

count

0..64

returns true/false depending if the led count was set