Struct blinkstick_rs::BlinkStick[][src]

pub struct BlinkStick {
    pub max_leds: u8,
    // some fields omitted
}

Fields

max_leds: u8

Implementations

Opens communication with a BlinkStick Device

Panics

When there is no connected BlinkStick device, the call to new will panic.

Turns off a single led

Arguments
  • led - A zero-indexed led number (within bounds for the BlinkStick product)

Turns off multiple leds

Arguments
  • leds - Zero-indexed led numbers (within bounds for the BlinkStick product)

Turns off all leds

Generates a random color

Example

Returns a random Color

use blinkstick_rs::{BlinkStick, Color};
let blinkstick = BlinkStick::new().unwrap();

let color = BlinkStick::get_random_color();

Returns a Vector with an appropriate vector length for the plugged in BlinkStick device

Example

Returns a Color vector

use blinkstick_rs::{BlinkStick, Color};
let blinkstick = BlinkStick::new().unwrap();

let colors = blinkstick.get_color_vec();

Sets the RGB color of a single led

Arguments
  • led - A zero-indexed led number (within bounds for the BlinkStick product)
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to set_led_color will panic if the specified led is out of bounds for the connected BlinkStick device.

Example

Sets the color of the 0th led to red

use blinkstick_rs::{BlinkStick, Color};
let blinkstick = BlinkStick::new().unwrap();

blinkstick.set_led_color(0, Color {r: 50, g: 0, b: 0}).unwrap();

assert_eq!(blinkstick.get_led_color(0).unwrap(), Color {r: 50, g: 0, b: 0});

Sets the RGB color of one or more leds to a single color

Arguments
  • leds - A vector of zero-indexed led numbers (within bounds for the BlinkStick product)
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to set_multiple_leds_color will panic if any of the specified leds is out of bounds for the BlinkStick device.

Example

Sets the color of 0th, 2nd, 4th and 6th led to green.

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();
blinkstick.set_multiple_leds_color(&vec![0, 2, 4, 6], Color {r: 0, g: 50, b: 0}).unwrap();

Sets the same color for all leds available on the BlinkStick device

Arguments
  • color - A struct holding color values for R,G and B channel respectively
Example

Turns every led blue

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();
blinkstick.set_all_leds_color(Color {r: 0, g: 0, b: 50}).unwrap();

Sets a different color for every led available on the BlinkStick device

Arguments
  • colors - A vector of equal length to the number of leds available on the device.
Panics

The call to blink_led_color will panic if the length of the color vector is greater then the number of available leds

Example

Sets a different color for each led on the device

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();

let mut colors: Vec<Color> = blinkstick.get_color_vec();

for led in 0..blinkstick.max_leds as usize {
   colors[led] = BlinkStick::get_random_color();
}

blinkstick.set_all_leds_colors(&colors).unwrap();

Makes a specified led blink in a single color

Arguments
  • led - A zero-indexed led number (within bounds for the BlinkStick product)
  • delay - The delay between turning the light on and off
  • blinks - The number of times the light will blink
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to blink_led_color will panic if the specified led is out of bounds for the connected BlinkStick device.

Example

Makes the 0th led blink 5 times, once every second, with a purple glow

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();
blinkstick.blink_led_color(0, std::time::Duration::from_secs(1), 5, Color {r: 25, g: 0, b: 25}).unwrap();

Makes the specified leds blink in a single color

Arguments
  • leds - A vector of zero-indexed led numbers (within bounds for the BlinkStick product)
  • delay - The delay between turning the lights on and off
  • blinks - The number of times the lights will blink
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to blink_multiple_leds_color will panic if any of the specified leds is out of bounds for the BlinkStick device.

Example

Makes the zeroth and first led blink 2 times, once every 200 milliseconds, with a yellow glow

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();
blinkstick.blink_multiple_leds_color(&vec![0, 1], std::time::Duration::from_millis(200), 2, Color {r: 50, g: 50, b: 0}).unwrap();

Makes all leds blink in a single color

Arguments
  • delay - The delay between turning the lights on and off
  • blinks - The number of times the lights will blink
  • color - A struct holding color values for R,G and B channel respectively
Example

Makes all leds blink 2 times, once every 200 milliseconds, with a yellow glow

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();
blinkstick.blink_all_leds_color(std::time::Duration::from_millis(200), 2, Color {r: 50, g: 50, b: 0}).unwrap();

Makes the specified led pulse from its current color to a specified color and back again

Arguments
  • led - A zero-indexed led number (within bounds for the BlinkStick product)
  • duration - The time it takes for the entire animation cycle to finish
  • steps - The number of times the color changes are interpolated between the old and new color value
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to pulse_led_color will panic if the specified led is out of bounds for the connected BlinkStick device. The call to pulse_led_color will panic if the internal communication time is shorter then duration/steps.

Example

Makes the 2nd led, pulse from an off state, to a blue glow, and then return back again to the off state with a two second animation time

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();
blinkstick.pulse_led_color(2, std::time::Duration::from_secs(2), 20, Color {r: 0, g: 0, b: 155}).unwrap();

Makes the specified leds pulse to a single color and back to their original color

Arguments
  • leds - A vector of zero-indexed led numbers (within bounds for the BlinkStick product)
  • duration - The time it takes for the entire animation cycle to finish
  • steps - The number of times the color value is update during the transformation
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to pulse_multiple_leds_color will panic if any of the specified leds is out of bounds for the BlinkStick device. The call to pulse_multiple_leds_color will panic if the internal communication time is shorter then duration/steps.

Example

Gives the zeroth and fourth led a random color, and makes them pulse to a blue color

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();

let mut colors: Vec<Color> = blinkstick.get_color_vec();
colors[0] = BlinkStick::get_random_color();
colors[4] = BlinkStick::get_random_color();

blinkstick.set_all_leds_colors(&colors).unwrap();

let color = Color {r: 0, g: 0, b: 55};
blinkstick.pulse_multiple_leds_color(&vec![0, 4], std::time::Duration::from_secs(5), 50, color).unwrap();

assert_eq!(blinkstick.get_led_color(0).unwrap(), colors[0]);
assert_eq!(blinkstick.get_led_color(4).unwrap(), colors[4]);

Makes all leds pulse between their current color and a specified color

#Arguments

  • duration - The time it takes for the entire animation cycle to finish
  • steps - The number of times the color value is update during the transformation
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to pulse_all_leds_color will panic if the internal communication time is shorter then duration/steps.

Example

Makes every led pulse between being turned off and a green color

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();

blinkstick.pulse_all_leds_color(std::time::Duration::from_secs(2), 25, Color {r: 0, g: 25, b: 0}).unwrap();

assert_eq!(blinkstick.get_all_led_colors().unwrap(), vec![Color {r: 0, g: 0, b: 0}; blinkstick.max_leds as usize]);

Makes the specified led shift into a different color

Arguments
  • led - A zero-indexed led number (within bounds for the BlinkStick product)
  • duration - The time it takes for the entire animation cycle to finish
  • steps - The number of times the color value is update during the transformation
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to transform_led_color will panic if the specified led is out of bounds for the connected BlinkStick device. The call to transform_led_color will panic if the internal communication time is shorter then duration/steps.

Additionally, by choosing a very high step count, it makes the internal animation interval shorter then the function execution meaning that the animation would have taken longer then the specified duration to finish. Therefore, the function panics if this threshold is overstepped. A rule of thumb is for each second of animation, 100 steps is a softmax.

Example

Makes the first led transform from a red color into a green color over a period of five seconds, with 50 color updates.

use blinkstick_rs::{BlinkStick, Color};

let blinkstick = BlinkStick::new().unwrap();
blinkstick.set_led_color(1, Color {r: 50, g: 0, b: 0}).unwrap();
blinkstick.transform_led_color(1, std::time::Duration::from_secs(5), 50, Color {r: 0, g: 50, b: 0}).unwrap();

Transforms the color of all leds into a specified color on a per led basis

Arguments
  • duration - The time it takes for the entire animation cycle to finish
  • steps - The number of times the color value is update during the transformation
  • colors - A vector of Color with equal length to the number of leds available on the device.
Panics

The call to transform_all_leds_colors will panic if the internal communication time is shorter then duration/steps.

Additionally, by choosing a very high step count, it makes the internal animation interval shorter then the function execution meaning that the animation would have taken longer then the specified duration to finish. Therefore, the function panics if this threshold is overstepped. A rule of thumb is for each second of animation, 100 steps is a softmax.

Example

Sets a random color for each available led then transforms each individual led into a different random Color.

use blinkstick_rs::{BlinkStick, Color};
let blinkstick = BlinkStick::new().unwrap();

let mut colors: Vec<Color> = blinkstick.get_color_vec();
for led in 0..blinkstick.max_leds as usize {
    colors[led] = BlinkStick::get_random_color();
}

let mut new_colors: Vec<Color> = blinkstick.get_color_vec();
for led in 0..blinkstick.max_leds as usize {
    new_colors[led] = BlinkStick::get_random_color();
}

blinkstick.set_all_leds_colors(&colors).unwrap();
blinkstick.transform_all_leds_colors(std::time::Duration::from_secs(2), 50, &new_colors).unwrap();

Transforms the color of all leds into a specified color

Arguments
  • duration - The time it takes for the entire animation cycle to finish
  • steps - The number of times the color value is update during the transformation
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to transform_all_leds_color will panic if the internal communication time is shorter then duration/steps.

Example

Transforms all leds from “off” to a blue Color.

use blinkstick_rs::{BlinkStick, Color};
let blinkstick = BlinkStick::new().unwrap();

blinkstick.transform_all_leds_color(std::time::Duration::from_secs(2), 50, Color { r: 0, g: 0, b: 100 }).unwrap();

Transforms the color of the specified leds into a single color

Arguments
  • leds - A vector of zero-indexed led numbers (within bounds for the BlinkStick product)
  • duration - The time it takes for the entire animation cycle to finish
  • steps - The number of times the color value is update during the transformation
  • color - A struct holding color values for R,G and B channel respectively
Panics

The call to transform_multiple_leds_color will panic if any of the specified leds is out of bounds for the BlinkStick device. The call to transform_multiple_leds_color will panic if the internal communication time is shorter then duration/steps.

Example

Sets a random color for each available led then transforms it all into a single Color.

use blinkstick_rs::{BlinkStick, Color};
let blinkstick = BlinkStick::new().unwrap();

let mut colors: Vec<Color> = blinkstick.get_color_vec();

for led in 0..blinkstick.max_leds as usize {
    colors[led] = BlinkStick::get_random_color();
}

blinkstick.set_all_leds_colors(&colors).unwrap();

let led_vec: Vec<u8> = (0..blinkstick.max_leds).collect();
blinkstick.transform_multiple_leds_color(&led_vec, std::time::Duration::from_secs(2), 50, Color {r: 55, g: 0, b: 55}).unwrap();

Makes the blinkstick device carousel. A Carousel utilizes all leds to transition between start_color, stop_color and back to start_color

Arguments
  • start_color - The start color to transition from
  • stop_color - The target color to transition to
Example

Carousels the BlinkStick device Blue -> Green -> Blue 10 times

use blinkstick_rs::{BlinkStick, Color};
let blinkstick = BlinkStick::default();
let color_one = Color { r: 0, g: 0, b: 50 };
let color_two = Color {r: 0, g: 50, b: 0};
for _ in 0..10 {
    blinkstick.carousel(color_one, color_two, std::time::Duration::from_millis(20)).unwrap();
}

Gets the color of every single led on the BlinkStick device

Example

Gets the color of every single led

use blinkstick_rs::{BlinkStick, Color};
let blinkstick = BlinkStick::new().unwrap();
    
let random_color = BlinkStick::get_random_color();

blinkstick.set_led_color(1, random_color).unwrap();
blinkstick.set_led_color(2, random_color).unwrap();

let led_colors = blinkstick.get_all_led_colors().unwrap();

assert_ne!(led_colors[0], random_color);
assert_eq!(led_colors[1], random_color);
assert_eq!(led_colors[2], random_color);

Gets the color of a single led on the BlinkStick device

Example

Gets the color of the zeroth led

use blinkstick_rs::{BlinkStick, Color};
let blinkstick = BlinkStick::new().unwrap();
    
let random_color = BlinkStick::get_random_color();

blinkstick.set_led_color(0, random_color).unwrap();

let led_color = blinkstick.get_led_color(0).unwrap();

assert_eq!(led_color, random_color);

Trait Implementations

Returns the “default value” for a type. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.