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_positionswill be ignored. - Bytes with index greater than
TM1637::num_positionswill 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.
Nis the size of the internal window used to move the segments. SeeTM1637::move_segments_rawfor more information.Mis the maximum number of bytes that can be converted from theASCIIstring.
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 |
+---+ +---+ +---+ +---+