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§
source§impl Blinkt
impl Blinkt
sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Constructs 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<Self>
pub fn with_settings( pin_data: u8, pin_clock: u8, num_pixels: usize ) -> Result<Self>
Constructs 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(spi: BlinktSpi, num_pixels: usize) -> Self
pub fn with_spi(spi: BlinktSpi, num_pixels: usize) -> Self
Constructs 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 125 MHz (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. 32 MHz (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 iter_mut(&mut self) -> IterMut<'_, Pixel>
pub fn iter_mut(&mut self) -> IterMut<'_, Pixel>
Returns a mutable iterator over all Pixel
s stored in Blinkt
.
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.
Pixels are numbered starting at 0
.
red
, green
and blue
are specified as 8-bit values between 0
(0%) and 255
(100%).
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.
Pixels are numbered starting at 0
.
red
, green
and blue
are specified as 8-bit values between 0
(0%) and 255
(100%).
brightness
is specified as a floating point value between 0.0
(0%) and 1.0
(100%), and 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.
Pixels are numbered starting at 0
.
brightness
is specified as a floating point value between 0.0
(0%) and 1.0
(100%), and 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.
red
, green
and blue
are specified as 8-bit values between 0
(0%) and 255
(100%).
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.
red
, green
and blue
are specified as 8-bit values between 0
(0%) and 255
(100%).
brightness
is specified as a floating point value between 0.0
(0%) and 1.0
(100%), and 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.
brightness
is specified as a floating point value between 0.0
(0%) and 1.0
(100%), and is converted to a 5-bit value.
sourcepub fn show(&mut self) -> Result<()>
pub fn show(&mut self) -> Result<()>
Sends the contents of the local buffer to the pixels, updating their LED colors and brightness.
sourcepub fn clear_on_drop(&self) -> bool
pub fn clear_on_drop(&self) -> bool
Returns the value of clear_on_drop
.
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 Blinkt
goes out of scope.
By default, this is set to true
.
Note
Drop methods aren’t called when a process is abnormally terminated, for
instance when a user presses Ctrl + C, and the SIGINT
signal
isn’t caught. You can catch those using crates such as simple_signal
.