[][src]Crate blinkt

A Rust library that provides an interface for the Pimoroni Blinkt!, and any similar APA102 or SK9822 LED strips or boards, on a Raspberry Pi. The library supports bitbanging mode on any GPIO pins, and hardware SPI mode on GPIO 10 (physical pin 19) for data, and GPIO 11 (physical pin 23) for clock.

For bitbanging mode, Blinkt gains access to the BCM283x GPIO peripheral either through /dev/gpiomem or /dev/mem. Hardware SPI mode is controlled through /dev/spidev0.0.

Both the original APA102 and the SK9822 clone are supported. The APA102 RGB LED/driver ICs are referred to as pixels throughout the code and documentation.

Each pixel has a red, green and blue LED with possible values between 0-255. Additionally, the overall brightness of each pixel can be set to 0.0-1.0, which is converted to a 5-bit value.

Blinkt stores all color and brightness changes in a local buffer. Use show() to send the buffered values to the pixels.

By default, all pixels are cleared when Blinkt goes out of scope. Use set_clear_on_drop(false) to disable this behavior. Note that drop methods aren't called when a program is abnormally terminated (for instance when a SIGINT isn't caught).


Blinkt! board

A complete example that cycles all pixels on a Blinkt! board through red, green and blue.

extern crate blinkt;

use std::{thread, mem};
use std::time::Duration;

use blinkt::Blinkt;

fn main() {
    let mut blinkt = Blinkt::new().unwrap();
    let (red, green, blue) = (&mut 255, &mut 0, &mut 0);

    loop {
        blinkt.set_all_pixels(*red, *green, *blue);


        mem::swap(red, green);
        mem::swap(red, blue);

APA102 or SK9822 LED strip

The recommended way to control an LED strip is to use the hardware SPI interface through Blinkt::with_spi(), with the data line connected to GPIO 10 (physical pin 19), and clock on GPIO 11 (physical pin 23).

let mut blinkt = Blinkt::with_spi(16_000_000, 144).unwrap();

Alternatively, you can use the bitbanging mode through Blinkt::with_settings() to connect the LED strip to any available GPIO pins. However, this is less reliable than using the hardware SPI interface, and may cause issues on longer strips.

let mut blinkt = Blinkt::with_settings(23, 24, 8).unwrap();



Interface for the Pimoroni Blinkt!, and any similar APA102 or SK9822 LED strips or boards.



Errors that can occur while using Blinkt.


Errors that can occur when accessing the GPIO peripheral.


Errors that can occur when accessing the SPI peripheral.

Type Definitions


Result type returned from methods that can have blinkt::Errors.