Skip to main content

Crate sevseg_3642bs

Crate sevseg_3642bs 

Source
Expand description

Driver crate for the 3642BS 4 digit 7 segment display

[Datasheet link]

§How to use

Create a new display object by calling .new() and passing the GPIO pins the display is connected to. It is necessary for your HAL to use embedded_hal::digital::v2::OutputPin

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 // Your HAL's delay object 
);

Once the display has been defined, the other methods can be called, for example:

display.clear().unwrap();
display.number(1234).unwrap();
display.hex(0xAB12).unwrap();

.number(), .hex() and .time() Will return a DisplayErr result which can be matched:

if let Err(err) = display.time(13, 37) {
    match err {
        DisplayErr::PinFail => info!("Failed to write to a pin!");
        DisplayErr::OutOfRange => info!("One of the numbers is too large!")
    }
}

You can make your own custom charcaters by specifying which segments should turn on on a bitwise or operation:

let letter_c = SEG_A | SEG_F | SEG_E | SEG_D;
let letter_o = SEG_G | SEG_C | SEG_D | SEG_E;
let letter_l = SEG_F | SEG_E | SEG_D;

(The segment names are indicated on the datasheet)

.custom() takes an array with 4 values, each corresponding to one digit. The following example demonstrates how to write CooL to the display:

let text_cool = [letter_c, letter_o, letter_o, letter_l];
display.custom(text_cool).unwrap();

Structs§

Display
To use the display you’ll need to pass the microcontroller’s pins and the delay object in your HAL.

Enums§

DisplayErr
Error type returned by the .number(), .hex() and .time() methods

Constants§

SEG_A
Will turn on the segment A when used in .custom(). Can be used in combination with other segment constants combining them with the or ( | ) operator
SEG_B
Will turn on the segment B when used in .custom(). Can be used in combination with other segment constants combining them with the or ( | ) operator
SEG_C
Will turn on the segment C when used in .custom(). Can be used in combination with other segment constants combining them with the or ( | ) operator
SEG_D
Will turn on the segment D when used in .custom(). Can be used in combination with other segment constants combining them with the or ( | ) operator
SEG_E
Will turn on the segment E when used in .custom(). Can be used in combination with other segment constants combining them with the or ( | ) operator
SEG_F
Will turn on the segment F when used in .custom(). Can be used in combination with other segment constants combining them with the or ( | ) operator
SEG_G
Will turn on the segment G when used in .custom(). Can be used in combination with other segment constants combining them with the or ( | ) operator
SEG_SD
Will turn on the two dots when used in .custom(). Can be used in combination with other segment constants combining them with the or ( | ) operator. Note that only one of the common anodes connects to the two dots.