#driver #led-driver #3461bs

no-std driver-3461bs-rs

3461BS LED驱动器驱动程序

2个版本

0.1.2 2024年4月28日
0.1.1 2024年4月28日
0.1.0 2024年4月28日

#459 in 嵌入式开发

MIT 协议

11KB
250

适用于3461BS 4位7段显示器的平台无关Rust驱动程序

这是一个超级简单的Rust驱动程序,用于任何4位7段显示器,目前仅在3461BS1上进行了测试,但理论上它应该适用于任何显示器。如果您发现不同的显示器或板上有任何错误,请告知我。

示例

带有Raspberry Pi Pico的工作示例。

以下是3461BS1的引脚图:

let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());

// Setup for all the required pins
let  mut  e  =  pins.gpio1.into_push_pull_output();
let  mut  d  =  pins.gpio2.into_push_pull_output();
let  mut  dp  =  pins.gpio3.into_push_pull_output();
let  mut  c  =  pins.gpio4.into_push_pull_output();
let  mut  g  =  pins.gpio5.into_push_pull_output();
let  mut  d4  =  pins.gpio6.into_push_pull_output();
let  mut  d1  =  pins.gpio7.into_push_pull_output();
let  mut  a  =  pins.gpio8.into_push_pull_output();
let  mut  f  =  pins.gpio9.into_push_pull_output();
let  mut  d2  =  pins.gpio10.into_push_pull_output();
let  mut  d3  =  pins.gpio11.into_push_pull_output();
let  mut  b  =  pins.gpio12.into_push_pull_output();

// Creating the LED3461BS
let  mut  led_display  =  LED3461BS1::new(
&mut  a, &mut  b, &mut  c, &mut  d, &mut  e, &mut  f, &mut  g, &mut  dp, &mut  d1, &mut  d2,
&mut  d3, &mut  d4,
);

// Displaying characters 2 3 4 C on the board
// Delay 5 milliseconds before settings the next digit, due to the optical illusion of [persistance of vision](https://en.wikipedia.org/wiki/Persistence_of_vision)
loop {
	// To set a number, first parameter is a char with the digit you want it to be on
	// Second parameter is a char with the number on the digit
	led_display.set_number_on_digit('1', '2').unwrap();
	delay.delay_ms(5);
	led_display.clear();
	led_display.set_number_on_digit('2', '3').unwrap();
	delay.delay_ms(5);
	led_display.clear();
	led_display.set_number_on_digit('2', '4').unwrap();
	delay.delay_ms(5);
	led_display.clear();
	led_display.set_number_on_digit('2', '5').unwrap();
	delay.delay_ms(5);
	led_display.clear();
	// To set a custom character, first parameter should be the digit you want it to be on
	// The next parameters are segments a-g
	// The last parameter is the decimal point
	// Look at the pinout of the 3461BS1
	led_display
	.set_custom_character('4', true, false, false, true, true, true, false, false)
	.unwrap();
}

依赖项

~2MB
~41K SLoC