Struct Multiplexer

Source
pub struct Multiplexer<Pins> {
    pub pins: Pins,
    pub num_channels: u8,
    pub active_channel: u8,
    pub enabled: bool,
}
Expand description

Provides an interface for setting the active channel and enabling/disabling an 8-channel (74HC4051) or 16-channel (74HC4067) analog multiplexer. It also keeps track of which channel is currently active (active_channel) and provides a convenient num_channels field that can be used to iterate over all the multiplexer’s channels.

Fields§

§pins: Pins§num_channels: u8§active_channel: u8§enabled: bool

Implementations§

Source§

impl<Pins: Output> Multiplexer<Pins>

Source

pub fn new(pins: Pins) -> Self

Given a 5 or 4-member tuple, (s0, s1, s2, s3, en) or (s0, s1, s2, en) where every member is an OutputPin, returns a new instance of Multiplexer for a 16-channel or 8-channel analog multiplexer, respectively.

NOTE: Some multiplexers label S0-S3 as A-D. They’re the same thing.

Source

pub fn set_channel(&mut self, channel: u8)

Sets the current active channel on the multiplexer (0 up to num_channels) and records that state in self.active_channel

Source

pub fn enable(&mut self)

Enables the multiplexer and sets self.enabled = true

Source

pub fn disable(&mut self)

Disables the multiplexer and sets self.enabled = false

Auto Trait Implementations§

§

impl<Pins> Freeze for Multiplexer<Pins>
where Pins: Freeze,

§

impl<Pins> RefUnwindSafe for Multiplexer<Pins>
where Pins: RefUnwindSafe,

§

impl<Pins> Send for Multiplexer<Pins>
where Pins: Send,

§

impl<Pins> Sync for Multiplexer<Pins>
where Pins: Sync,

§

impl<Pins> Unpin for Multiplexer<Pins>
where Pins: Unpin,

§

impl<Pins> UnwindSafe for Multiplexer<Pins>
where Pins: 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.