Struct EightSegment

Source
pub struct EightSegment<'a> {
    pub high_on: bool,
    pub seg_a: &'a mut dyn OutputPin,
    pub seg_b: &'a mut dyn OutputPin,
    pub seg_c: &'a mut dyn OutputPin,
    pub seg_d: &'a mut dyn OutputPin,
    pub seg_e: &'a mut dyn OutputPin,
    pub seg_f: &'a mut dyn OutputPin,
    pub seg_g: &'a mut dyn OutputPin,
    pub seg_p: &'a mut dyn OutputPin,
}
Expand description

An eight segment display that can display a single digit from 0x0 to 0xF at a time. Intended for use with the HDSP-H101 and HDSP-H103.

The labels on the segments are as described in the H101 and H103 datasheet:

    _______
   |   a   |
   |f     b|
   |   g   |
   |-------|
   |e     c|
   |   d   |
   '-------'  .
              p

Some like the H101 have the segment turned on being pin-low, and some like the H103 have on being pin-high. Set the high_on boolean as appropriate.

§Examples

    // in this case using the `atsamd21_hal` library to provide access to the pins
    // but any embedded-hal implementation should work
    let mut peripherals = Peripherals::take().unwrap();
    let mut pins = peripherals.PORT.split();
    let mut seg_a = pins.pa21.into_open_drain_output(&mut pins.port);
    let mut seg_b = pins.pa20.into_open_drain_output(&mut pins.port);
    let mut seg_c = pins.pa11.into_open_drain_output(&mut pins.port);
    let mut seg_d = pins.pb10.into_open_drain_output(&mut pins.port);
    let mut seg_e = pins.pb11.into_open_drain_output(&mut pins.port);
    let mut seg_f = pins.pa16.into_open_drain_output(&mut pins.port);
    let mut seg_g = pins.pa17.into_open_drain_output(&mut pins.port);
    let mut seg_p = pins.pa10.into_open_drain_output(&mut pins.port);
    let mut eight_segment = EightSegment {
        high_on: false,
        seg_a: &mut seg_a,
        seg_b: &mut seg_b,
        seg_c: &mut seg_c,
        seg_d: &mut seg_d,
        seg_e: &mut seg_e,
        seg_f: &mut seg_f,
        seg_g: &mut seg_g,
        seg_p: &mut seg_p,
    };
    eight_segment.blank(); // All segments off
    eight_segment.display(0xb, false); // Display 'b' with decimal point off

Fields§

§high_on: bool§seg_a: &'a mut dyn OutputPin§seg_b: &'a mut dyn OutputPin§seg_c: &'a mut dyn OutputPin§seg_d: &'a mut dyn OutputPin§seg_e: &'a mut dyn OutputPin§seg_f: &'a mut dyn OutputPin§seg_g: &'a mut dyn OutputPin§seg_p: &'a mut dyn OutputPin

Implementations§

Source§

impl<'a> EightSegment<'a>

Source

pub fn blank(&mut self)

Source

pub fn set_segments( &mut self, seg_a_on: bool, seg_b_on: bool, seg_c_on: bool, seg_d_on: bool, seg_e_on: bool, seg_f_on: bool, seg_g_on: bool, seg_p_on: bool, )

Source

pub fn display(&mut self, count: u8, seg_p_on: bool)

Auto Trait Implementations§

§

impl<'a> Freeze for EightSegment<'a>

§

impl<'a> !RefUnwindSafe for EightSegment<'a>

§

impl<'a> !Send for EightSegment<'a>

§

impl<'a> !Sync for EightSegment<'a>

§

impl<'a> Unpin for EightSegment<'a>

§

impl<'a> !UnwindSafe for EightSegment<'a>

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.