blinkt 0.1.1

Provides an interface for the Pimoroni Blinkt!, and any similar APA102 strips or boards, on a Raspberry Pi.

Crate blinkt [] [src]

A Rust library that provides an interface for the Pimoroni Blinkt!, and any similar APA102 strips or boards, on a Raspberry Pi.

Blinkt accesses the BCM2708/BCM2709 GPIO peripheral either through /dev/gpiomem (preferred) or /dev/mem. Both the original APA102, and the alternate version with a smaller, darker die, 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.

Examples

A complete example that cycles all pixels 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);
        blinkt.show();

        thread::sleep(Duration::from_millis(250));

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

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).

use blinkt::Blinkt;

let mut blinkt = Blinkt::new().unwrap();
blinkt.set_clear_on_drop(false);

for n in 0..8 {
    blinkt.set_pixel(n, 36 * n as u8, 0, 255 - (36 * n as u8));
}

blinkt.show();

Structs

Blinkt

Interface for a Blinkt! or any similar APA102 strips/boards.

Enums

Error

Errors that can occur when creating a new Blinkt.

GPIOError

Errors that can occur when accessing the GPIO peripheral.

Type Definitions

Result

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