3个版本 (破坏性更新)
0.2.0 | 2024年1月17日 |
---|---|
0.1.0 | 2022年10月17日 |
0.0.1 | 2022年2月6日 |
#1506 in 嵌入式开发
16KB
286 行
智能LED矩阵
一个使用(一个或多个)智能LED矩阵作为图形显示的DrawTarget
实现,由嵌入式图形 Drawable
对象驱动。集成的驱动程序来自smart-leds包。
已知问题(以我的设置为例:stm32f401 + 8x8 ws2812矩阵)
- 使用相同参数绘制的圆并不总是在相同的位置,不确定这在大分辨率显示上是否相同。
- 写入操作通常会返回溢出错误,而显示仍然大约每秒更新一次(解决方案:始终刷新两次)。
计划
- 添加更多显示类型(如2x2或1x4的8x8矩阵网格),尽管用户可以通过实现另一个
layout
随时添加这些。
使用方法
您可以从创建一个用于您的LED和控制器驱动程序开始。一些示例可以在这里找到。
一旦有了它,您就可以将其插入由该包实现的DrawTarget
。
示例
use ws2812_spi as ws2812;
use smart_leds_matrix::{SmartLedMatrix, layout::Rectangular};
use embedded_graphics::{
pixelcolor::*,
prelude::*,
primitives::{
PrimitiveStyleBuilder, Rectangle,
},
};
fn main() -> ! {
[...]
let ws = ws2812::Ws2812::new(spi);
let mut matrix = SmartLedMatrix::<_, _, {8 * 8}>::new(ws, Rectangular::new_inverted_y(8, 8));
matrix.set_brightness(15);
matrix.clear(Rgb888::new(0, 0, 0));
// Drawable objects are calling draw_iter() function of the matrix.
// That is, only the internal frame buffer is updated, no real
// communication happens yet. That is useful when a frame is composed
// of multiple objects, text, etc.
Rectangle::new(Point::new(1, 1), Size::new(6, 6))
.into_styled(
PrimitiveStyleBuilder::new()
.fill_color(Rgb888::RED)
.build(),
).draw(&mut matrix)?;
// Trigger the actual frame update on the matrix with gamma correction.
matrix.flush_with_gamma();
loop{}
}
依赖关系
~715KB
~12K SLoC