Struct sevseg_3642bs::Display
source · pub struct Display<A, B, C, D, E, F, G, SD, D1, D2, D3, D4, DL> { /* private fields */ }
Expand description
To use the display you’ll need to pass the microcontroller’s pins and the delay object in your HAL.
The example uses pins 12-26, but any GPIO pin can be used for any of the fields.
let mut display = SevenSeg::new(
pins.gpio16.into_push_pull_output(), // Segment A
pins.gpio17.into_push_pull_output(), // Segment B
pins.gpio18.into_push_pull_output(), // Segment C
pins.gpio19.into_push_pull_output(), // Segment D
pins.gpio20.into_push_pull_output(), // Segment E
pins.gpio21.into_push_pull_output(), // Segment F
pins.gpio22.into_push_pull_output(), // Segment G
pins.gpio26.into_push_pull_output(), // Dots segment
pins.gpio15.into_push_pull_output(), // Digit 0 common anode
pins.gpio14.into_push_pull_output(), // Digit 1 common anode
pins.gpio13.into_push_pull_output(), // Digit 2 common anode
pins.gpio12.into_push_pull_output(), // Digit 3 common anode
delay,
);
Implementations§
source§impl<A, B, C, D, E, F, G, SD, D1, D2, D3, D4, DL> Display<A, B, C, D, E, F, G, SD, D1, D2, D3, D4, DL>where
A: OutputPin,
B: OutputPin,
C: OutputPin,
D: OutputPin,
E: OutputPin,
F: OutputPin,
G: OutputPin,
SD: OutputPin,
D1: OutputPin,
D2: OutputPin,
D3: OutputPin,
D4: OutputPin,
DL: DelayMs<u8>,
Infallible: From<<A as OutputPin>::Error> + From<<B as OutputPin>::Error> + From<<C as OutputPin>::Error> + From<<D as OutputPin>::Error> + From<<E as OutputPin>::Error> + From<<F as OutputPin>::Error> + From<<G as OutputPin>::Error> + From<<SD as OutputPin>::Error> + From<<D1 as OutputPin>::Error> + From<<D2 as OutputPin>::Error> + From<<D3 as OutputPin>::Error> + From<<D4 as OutputPin>::Error>,
impl<A, B, C, D, E, F, G, SD, D1, D2, D3, D4, DL> Display<A, B, C, D, E, F, G, SD, D1, D2, D3, D4, DL>where A: OutputPin, B: OutputPin, C: OutputPin, D: OutputPin, E: OutputPin, F: OutputPin, G: OutputPin, SD: OutputPin, D1: OutputPin, D2: OutputPin, D3: OutputPin, D4: OutputPin, DL: DelayMs<u8>, Infallible: From<<A as OutputPin>::Error> + From<<B as OutputPin>::Error> + From<<C as OutputPin>::Error> + From<<D as OutputPin>::Error> + From<<E as OutputPin>::Error> + From<<F as OutputPin>::Error> + From<<G as OutputPin>::Error> + From<<SD as OutputPin>::Error> + From<<D1 as OutputPin>::Error> + From<<D2 as OutputPin>::Error> + From<<D3 as OutputPin>::Error> + From<<D4 as OutputPin>::Error>,
sourcepub const fn new(
seg_a: A,
seg_b: B,
seg_c: C,
seg_d: D,
seg_e: E,
seg_f: F,
seg_g: G,
seg_dots: SD,
dig_1: D1,
dig_2: D2,
dig_3: D3,
dig_4: D4,
delay: DL
) -> Self
pub const fn new( seg_a: A, seg_b: B, seg_c: C, seg_d: D, seg_e: E, seg_f: F, seg_g: G, seg_dots: SD, dig_1: D1, dig_2: D2, dig_3: D3, dig_4: D4, delay: DL ) -> Self
Creates a new display object from the pins you pass it.
Order: A, B, C, D, E, F, G, SD, D1, D2, D3, D4.
D1, D2, D3 and D4
are the common anodes.
_______
/-\__A__/-\
| | | |
|F| |B|
| | | |
\ /-----\ /
/ \__G__/ \
| | | |
|E| |C|
| |_____| |
\_/__D__\_/ __
|SD|
--
sourcepub fn clear(&mut self) -> Result<(), Infallible>
pub fn clear(&mut self) -> Result<(), Infallible>
Pulls the common anodes low, turning off the display.
Errors
Will return an error if it fails to set the pins low.
sourcepub fn custom(&mut self, digits: [u8; 4]) -> Result<(), Infallible>
pub fn custom(&mut self, digits: [u8; 4]) -> Result<(), Infallible>
You can make your own custom charcaters by writing which segments should turn on:
let letter_a: u8 = SEG_A | SEG_B | SEG_C | SEG_E | SEG_F | SEG_G
The .custom() function modifies the 4 digits, so you’ll have to pass an array with the value for the four digits.
let custom_msg: [u8; 4] = [0, 0, 0, letter_a];
display.custom(custom_msg);
Errors
Will return an error if it fails to set the state of any of the pins
sourcepub fn number(&mut self, number: i32) -> Result<(), DisplayErr>
pub fn number(&mut self, number: i32) -> Result<(), DisplayErr>
Displays a 4 digit number between -1999 and 9999.
Errors
Will return an error if the number is not in the range or if the .custom() call inside returns an error.