Skip to main content

Pixels

Struct Pixels 

Source
pub struct Pixels<I2C> { /* private fields */ }
Expand description

Driver for the Modulino Pixels module.

§Example

use modulino::{Pixels, Color};

let mut pixels = Pixels::new(i2c)?;

// Set individual LED
pixels.set_color(0, Color::RED, 50)?;

// Set all LEDs to the same color
pixels.set_all_color(Color::BLUE, 25)?;

// Apply changes
pixels.show()?;

// Clear all LEDs
pixels.clear_all()?;
pixels.show()?;

Implementations§

Source§

impl<I2C, E> Pixels<I2C>
where I2C: I2c<Error = E>,

Source

pub fn new(i2c: I2C) -> Result<Self, E>

Create a new Pixels instance with the default address.

Source

pub fn new_with_address(i2c: I2C, address: u8) -> Result<Self, E>

Create a new Pixels instance with a custom address.

Source

pub fn address(&self) -> u8

Get the I2C address.

Source

pub fn set_color( &mut self, index: usize, color: Color, brightness: u8, ) -> Result<&mut Self, E>

Set the color of a specific LED.

§Arguments
  • index - LED index (0-7)
  • color - The color to set
  • brightness - Brightness level (0-100)
Source

pub fn set_rgb( &mut self, index: usize, r: u8, g: u8, b: u8, brightness: u8, ) -> Result<&mut Self, E>

Set the color of a specific LED using RGB values.

§Arguments
  • index - LED index (0-7)
  • r - Red component (0-255)
  • g - Green component (0-255)
  • b - Blue component (0-255)
  • brightness - Brightness level (0-100)
Source

pub fn set_brightness( &mut self, index: usize, brightness: u8, ) -> Result<&mut Self, E>

Set the brightness of a specific LED without changing its color.

§Arguments
  • index - LED index (0-7)
  • brightness - Brightness level (0-100)
Source

pub fn set_all_color(&mut self, color: Color, brightness: u8) -> &mut Self

Set the color of all LEDs.

Source

pub fn set_all_rgb(&mut self, r: u8, g: u8, b: u8, brightness: u8) -> &mut Self

Set all LEDs to the same RGB color.

Source

pub fn set_range_color( &mut self, from: usize, to: usize, color: Color, brightness: u8, ) -> &mut Self

Set the color of a range of LEDs.

§Arguments
  • from - Starting index (inclusive)
  • to - Ending index (inclusive)
  • color - The color to set
  • brightness - Brightness level (0-100)
Source

pub fn set_all_brightness(&mut self, brightness: u8) -> &mut Self

Set the brightness of all LEDs without changing their colors.

Source

pub fn clear(&mut self, index: usize) -> Result<&mut Self, E>

Clear (turn off) a specific LED.

Source

pub fn clear_range(&mut self, from: usize, to: usize) -> &mut Self

Clear a range of LEDs.

Source

pub fn clear_all(&mut self) -> &mut Self

Clear all LEDs.

Source

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

Apply the current LED states to the hardware.

This must be called after setting colors for changes to take effect.

Source

pub fn set_color_show( &mut self, index: usize, color: Color, brightness: u8, ) -> Result<(), E>

Set a color and immediately show it.

Source

pub fn release(self) -> I2C

Release the I2C bus.

Auto Trait Implementations§

§

impl<I2C> Freeze for Pixels<I2C>
where I2C: Freeze,

§

impl<I2C> RefUnwindSafe for Pixels<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for Pixels<I2C>
where I2C: Send,

§

impl<I2C> Sync for Pixels<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for Pixels<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for Pixels<I2C>
where I2C: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.