pub struct Blinkt { /* private fields */ }
Expand description
Interface for the Pimoroni Blinkt!, and any similar APA102 or SK9822 LED strips or boards.
By default, Blinkt is set up to communicate with an 8-pixel board through data pin GPIO 23 (physical pin 16) and clock pin GPIO 24 (physical pin 18). These settings can be changed to support alternate configurations.
Implementations
sourceimpl Blinkt
impl Blinkt
sourcepub fn new() -> Result<Blinkt>
pub fn new() -> Result<Blinkt>
Creates a new Blinkt
using the default settings for a Pimoroni
Blinkt! board.
This sets the data pin to GPIO 23 (physical pin 16), the clock pin to GPIO 24 (physical pin 18), and number of pixels to 8.
sourcepub fn with_settings(
pin_data: u8,
pin_clock: u8,
num_pixels: usize
) -> Result<Blinkt>
pub fn with_settings(
pin_data: u8,
pin_clock: u8,
num_pixels: usize
) -> Result<Blinkt>
Creates a new Blinkt
using bitbanging mode, with custom settings for
the data pin, clock pin, and number of pixels. Pins should be specified
by their BCM GPIO pin numbers.
sourcepub fn with_spi(clock_speed_hz: u32, num_pixels: usize) -> Result<Blinkt>
pub fn with_spi(clock_speed_hz: u32, num_pixels: usize) -> Result<Blinkt>
Creates a new Blinkt
using hardware SPI, with custom settings for the
clock speed and number of pixels.
This sets the data pin to GPIO 10 (physical pin 19) and the clock pin to GPIO 11 (physical pin 23).
The Raspberry Pi allows SPI clock speeds up to 125MHz (125_000_000), but the maximum speed supported by LED strips depends a lot on the number of pixels and wire quality, and requires some experimentation. 32MHz (32_000_000) seems to be the maximum clock speed for a typical short LED strip. Visit the Raspberry Pi SPI Documentation page for a complete list of supported clock speeds.
sourcepub fn set_clear_on_drop(&mut self, clear_on_drop: bool)
pub fn set_clear_on_drop(&mut self, clear_on_drop: bool)
When enabled, clears all pixels when the Blinkt
goes out of scope.
Drop methods aren’t called when a program is abnormally terminated,
for instance when a user presses Ctrl-C, and the SIGINT signal isn’t
caught. You’ll either have to catch those using crates such as
simple_signal
, or manually call cleanup()
.
Enabled by default.
sourcepub fn cleanup(&mut self) -> Result<()>
pub fn cleanup(&mut self) -> Result<()>
Changes the GPIO pin mode for the data and clock pins back to their original state, and optionally clears all pixels.
Normally, this method is automatically called when Blinkt goes out of scope, but you can manually call it to handle early/abnormal termination.
sourcepub fn set_pixel(&mut self, pixel: usize, red: u8, green: u8, blue: u8)
pub fn set_pixel(&mut self, pixel: usize, red: u8, green: u8, blue: u8)
Sets the red, green and blue values for a single pixel in the local buffer.
For an 8-pixel board, valid values for pixel are 0-7. Valid values for red, green and blue are 0-255.
sourcepub fn set_pixel_rgbb(
&mut self,
pixel: usize,
red: u8,
green: u8,
blue: u8,
brightness: f32
)
pub fn set_pixel_rgbb(
&mut self,
pixel: usize,
red: u8,
green: u8,
blue: u8,
brightness: f32
)
Sets the red, green, blue and brightness values for a single pixel in the local buffer.
For an 8-pixel board, valid values for pixel are 0-7. Valid values for red, green and blue are 0-255. Valid values for brightness are 0.0-1.0, which is converted to a 5-bit value.
sourcepub fn set_pixel_brightness(&mut self, pixel: usize, brightness: f32)
pub fn set_pixel_brightness(&mut self, pixel: usize, brightness: f32)
Sets the brightness value for a single pixel in the local buffer.
For an 8-pixel board, valid values for pixel are 0-7. Valid values for brightness are 0.0-1.0, which is converted to a 5-bit value.
sourcepub fn set_all_pixels(&mut self, red: u8, green: u8, blue: u8)
pub fn set_all_pixels(&mut self, red: u8, green: u8, blue: u8)
Sets the red, green and blue values for all pixels in the local buffer.
Valid values for red, green and blue are 0-255.
sourcepub fn set_all_pixels_rgbb(&mut self, red: u8, green: u8, blue: u8, brightness: f32)
pub fn set_all_pixels_rgbb(&mut self, red: u8, green: u8, blue: u8, brightness: f32)
Sets the red, green, blue and brightness values for all pixels in the local buffer.
Valid values for red, green and blue are 0-255. Valid values for brightness are 0.0-1.0, which is converted to a 5-bit value.
sourcepub fn set_all_pixels_brightness(&mut self, brightness: f32)
pub fn set_all_pixels_brightness(&mut self, brightness: f32)
Sets the brightness value for all pixels in the local buffer.
Valid values for brightness are 0.0-1.0, which is converted to a 5-bit value.