Struct blinkt::Blinkt

source ·
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

source

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.

source

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.

source

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.

source

pub fn iter_mut(&mut self) -> IterMut<'_, Pixel>

Returns a mutable iterator over all Pixels stored in Blinkt.

source

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

source

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.

source

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.

source

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

source

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.

source

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.

source

pub fn clear(&mut self)

Sets the red, green and blue values for all pixels to 0.

source

pub fn show(&mut self) -> Result<()>

Sends the contents of the local buffer to the pixels, updating their LED colors and brightness.

source

pub fn clear_on_drop(&self) -> bool

Returns the value of clear_on_drop.

source

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.

Trait Implementations§

source§

impl Drop for Blinkt

source§

fn drop(&mut self)

Clears all pixels if clear_on_drop is set to true (default).

source§

impl<'a> IntoIterator for &'a mut Blinkt

§

type Item = &'a mut Pixel

The type of the elements being iterated over.
§

type IntoIter = IterMut<'a, Pixel>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Blinkt

§

impl Send for Blinkt

§

impl !Sync for Blinkt

§

impl Unpin for Blinkt

§

impl !UnwindSafe for Blinkt

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.