eg-seven-segment
is a seven-segment display text renderer for use with
embedded-graphics
. It can be used to display virtual seven-segment displays
on any embedded-graphics
DrawTarget
. The appearance of the drawn digits
can be configured to achieve a wide variety of styles.
The most convenient way to use this crate is by using the SevenSegmentStyle
as a
character style for an embedded-graphics
Text
:
use embedded_graphics::{prelude::*, text::Text, pixelcolor::Rgb888};
use eg_seven_segment::SevenSegmentStyleBuilder;
// Define a new style.
let style = SevenSegmentStyleBuilder::new()
.digit_size(Size::new(10, 20)) // digits are 10x20 pixels
.digit_spacing(5) // 5px spacing between digits
.segment_width(5) // 5px wide segments
.segment_color(Rgb888::GREEN) // active segments are green
.build();
// Use the style to draw text to a embedded-graphics `DrawTarget`.
Text::new("12:42", Point::new(5, 25), style).draw(&mut display)?;
Individual digits can also be drawn by using the Digit
drawable:
use embedded_graphics::{prelude::*, text::Text, pixelcolor::Rgb888};
use eg_seven_segment::{SevenSegmentStyleBuilder, Digit, Segments};
// Define a new style.
let style = SevenSegmentStyleBuilder::new()
.digit_size(Size::new(10, 20)) // digits are 10x20 pixels
.digit_spacing(5) // 5px spacing between digits
.segment_width(5) // 5px wide segments
.segment_color(Rgb888::GREEN) // active segments are green
.build();
// Draw digit with active segment A at the origin.
let next = Digit::new(Segments::A, Point::zero())
.into_styled(style)
.draw(&mut display)?;
// Draw `0` digit the the right of the previous digit.
Digit::new('0'.try_into().unwrap(), next)
.into_styled(style)
.draw(&mut display)?;
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.