7个版本
0.1.8 | 2024年6月19日 |
---|---|
0.1.7 | 2024年6月17日 |
0.1.0 | 2024年4月12日 |
#286 在 嵌入式开发
每月 440 次下载
8KB
62 代码行
从您的PC控制您的NeoPixel!
安装
cargo添加 neobridge-rust
设置(板子)
要直接从您的PC控制NeoPixel,您需要设置您的CircuitPython板以接收串行命令。这已经在 code.py
脚本中编程。按照以下步骤操作。
- 下载 code.py
- 移动到CircuitPython板(RP2040官方支持)
- 您需要编辑
code.py
以适应您的设置! (LED数量、引脚位置、顺序) - 运行脚本。脚本将在每次启动时运行。
设置(PC/Linux/MacOS)
现在板子已准备好进行串行通信,您可以直接从PC控制它。这可以让您编程许多有趣的灯光效果!下面的示例创建了一个类似于'加载'条的动画效果。
use neobridge_rust::{Neobridge, RGB};
fn main() {
let mut neobridge = Neobridge::new("COM3", 30);
neobridge.set_all(RGB(0, 0, 0));
neobridge.show();
let mut i = 0;
loop {
if (i == 30) {
i = 0;
}
neobridge.set_one(RGB(255, 255, 255), i);
neobridge.show();
std::thread::sleep(std::time::Duration::from_millis(50));
neobridge.set_all(RGB(0, 0, 0));
i += 1;
}
}
在您开始从PC控制之前,您需要输入板子的位置。
- 在Windows上,这通常在名为
COM3
的位置,这可能是不同的。 - 在Linux上,看起来像
/dev/ttyACM0
- 在MacOS上,名称看起来像
/dev/tty.usbmodem1d12
这些名称可能会有所不同!确保找到适合该板子的正确名称!
文档
let neobridge = Neobridge::new("COM3", 30);
/*
*Connects to the board and initializes a struct object.*
Args:
`port (str)`: Takes a `str` object to initialize the board.
`n_of_leds (u32)`: Number of LEDs on the board.
*/
neobridge.set_all(self, rgb: RGB)
/*
*Sets all LEDs on the board to the given RGB values.*
Args:
`rgb (RGB)`: RGB values to set.
*/
neobridge.set_one(self, rgb: RGB, index: u32)
/*
*Sets a single LED on the board to the given RGB values.*
Args:
rgb (RGB): RGB values to set.
index (u32): Index of the LED to set.
*/
neobridge.set_list(self, rgb_list: Vec<RGB>)
/*
*Gives the board a list of RGB values to set.*
Args:
rgb_list (Vec<RGB>): RGB list to set.
*/
neobridge.show(self)
/*
Sends a command to the board to update the LEDs.
*/
待办事项清单
- 创建板子的自动化安装器。
依赖项
~2MB
~43K SLoC