pub struct TM1637<CLK, DIO, DELAY> { /* private fields */ }
blocking
only.Expand description
TM1637
7-segment display driver.
Implementations§
source§impl<CLK, DIO, DELAY, ERR> TM1637<CLK, DIO, DELAY>
impl<CLK, DIO, DELAY, ERR> TM1637<CLK, DIO, DELAY>
sourcepub fn new(
clk: CLK,
dio: DIO,
delay: DELAY,
brightness: Brightness,
delay_us: u32,
num_positions: u8,
) -> Self
pub fn new( clk: CLK, dio: DIO, delay: DELAY, brightness: Brightness, delay_us: u32, num_positions: u8, ) -> Self
Create a new TM1637
instance.
sourcepub fn builder(
clk: CLK,
dio: DIO,
delay: DELAY,
) -> TM1637Builder<CLK, DIO, DELAY>
pub fn builder( clk: CLK, dio: DIO, delay: DELAY, ) -> TM1637Builder<CLK, DIO, DELAY>
Create a new TM1637Builder
instance.
sourcepub fn init(&mut self) -> Result<(), ERR>
pub fn init(&mut self) -> Result<(), ERR>
Initialize the display.
Clear the display and set the brightness level.
sourcepub fn write_segments_raw(
&mut self,
position: u8,
bytes: &[u8],
) -> Result<(), ERR>
pub fn write_segments_raw( &mut self, position: u8, bytes: &[u8], ) -> Result<(), ERR>
Write the given bytes to the display starting from the given position.
sourcepub fn write_segments_raw_iter<ITER: Iterator<Item = u8>>(
&mut self,
position: u8,
bytes: ITER,
) -> Result<(), ERR>
pub fn write_segments_raw_iter<ITER: Iterator<Item = u8>>( &mut self, position: u8, bytes: ITER, ) -> Result<(), ERR>
Write the given bytes to the display starting from the given position.
§Notes:
- Positions greater than
TM1637::num_positions
will be ignored. - Bytes with index greater than
TM1637::num_positions
will be ignored.
Brightness level will not be written to the device on each call. Make sure to call TM1637::write_brightness
or TM1637::init
to set the brightness level.
sourcepub fn write_brightness(&mut self, brightness: Brightness) -> Result<(), ERR>
pub fn write_brightness(&mut self, brightness: Brightness) -> Result<(), ERR>
Set TM1637::brightness
and write the brightness level to the display.
sourcepub fn move_segments_raw<const N: usize>(
&mut self,
position: u8,
bytes: &[u8],
delay_ms: u32,
) -> Result<(), ERR>
pub fn move_segments_raw<const N: usize>( &mut self, position: u8, bytes: &[u8], delay_ms: u32, ) -> Result<(), ERR>
Move all segments across the display starting and ending at position
.
If the length of the bytes is less than or equal to TM1637::num_positions
- position
, the bytes will only be written to the display.
N
is the size of the internal window used to move the segments. Please make sure that N
is equal to TM1637::num_positions
.
TM1637::num_positions
will be removed in the future in favor of a constant generic parameter representing the number of positions.
sourcepub fn write_ascii_str(
&mut self,
position: u8,
ascii_str: &str,
) -> Result<(), ERR>
pub fn write_ascii_str( &mut self, position: u8, ascii_str: &str, ) -> Result<(), ERR>
Convert an ASCII
string to a byte iterator using from_ascii_byte
and write the segments to the display using TM1637::write_segments_raw_iter
.
Only available when the mappings
feature of this library is activated.
§Example
Write the string "Err"
to the display:
let mut tm = TM1637::builder(clk_pin, dio_pin, delay)
.brightness(Brightness::L3)
.build();
tm.init().ok();
tm.write_ascii_str(0, "Err").ok();
On a 4-digit display
, this will look like this:
+---+ +---+ +---+ +---+
| E | | r | | r | | |
+---+ +---+ +---+ +---+
sourcepub fn move_ascii_str<const N: usize, const M: usize>(
&mut self,
position: u8,
ascii_str: &str,
delay_ms: u32,
) -> Result<(), ERR>
pub fn move_ascii_str<const N: usize, const M: usize>( &mut self, position: u8, ascii_str: &str, delay_ms: u32, ) -> Result<(), ERR>
Convert an ASCII
string to a byte array using from_ascii_byte
and move the segments across the display using TM1637::move_segments_raw
.
N
is the size of the internal window used to move the segments. SeeTM1637::move_segments_raw
for more information.M
is the maximum number of bytes that can be converted from theASCII
string.
Only available when the mappings
feature of this library is activated.
§Example
Move the string "HELLO "
across a 4-digit display
:
let mut tm = TM1637::builder(clk_pin, dio_pin, delay)
.brightness(Brightness::L3)
.build();
tm.init().ok();
// 4 is the actual number of positions on the display.
// 6 is the maximum number of bytes that can be converted from the ASCII string.
// In case of "HELLO ", all six bytes will be converted.
tm.move_ascii_str::<4, 6>(0, "HELLO ", 500).ok();
On a 4-digit display
, this will look like this:
+---+ +---+ +---+ +---+
| H | | E | | L | | L |
+---+ +---+ +---+ +---+
+---+ +---+ +---+ +---+
| E | | L | | L | | O |
+---+ +---+ +---+ +---+
+---+ +---+ +---+ +---+
| L | | L | | O | | |
+---+ +---+ +---+ +---+
+---+ +---+ +---+ +---+
| L | | O | | | | H |
+---+ +---+ +---+ +---+
+---+ +---+ +---+ +---+
| O | | | | H | | E |
+---+ +---+ +---+ +---+
+---+ +---+ +---+ +---+
| | | H | | E | | L |
+---+ +---+ +---+ +---+
+---+ +---+ +---+ +---+
| H | | E | | L | | L |
+---+ +---+ +---+ +---+
Trait Implementations§
Auto Trait Implementations§
impl<CLK, DIO, DELAY> Freeze for TM1637<CLK, DIO, DELAY>
impl<CLK, DIO, DELAY> RefUnwindSafe for TM1637<CLK, DIO, DELAY>
impl<CLK, DIO, DELAY> Send for TM1637<CLK, DIO, DELAY>
impl<CLK, DIO, DELAY> Sync for TM1637<CLK, DIO, DELAY>
impl<CLK, DIO, DELAY> Unpin for TM1637<CLK, DIO, DELAY>
impl<CLK, DIO, DELAY> UnwindSafe for TM1637<CLK, DIO, DELAY>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)