3个不稳定版本
0.2.0 | 2024年4月10日 |
---|---|
0.1.1 | 2024年3月23日 |
0.1.0 | 2024年3月14日 |
577 在 嵌入式开发
每月下载 28 次
17KB
236 代码行
PFC8574和PFC8575的管理器。
此crate是一个非常简单的硬件pcf8574和pcf8575管理器。
在ESP32 WROOM-32上进行了测试。
查看Rust文档。
兼容性
pcf857x-simple | embedded-hal |
---|---|
0.1.x | v0.2.x |
0.2.x | v0.2.x |
使用示例
use std::thread;
use std::time::Duration;
use esp_idf_hal::units::KiloHertz;
use esp_idf_sys as _;
use esp_idf_hal::peripherals::Peripherals;
use esp_idf_hal::i2c::I2cDriver;
use esp_idf_hal::i2c::config::Config;
use pcf857x_simple::pcf8574::Pcf8574;
use pcf857x_simple::{Pin, PinState, PCF857X_DEFAULT_ADDRESS};
fn main() {
esp_idf_sys::link_patches();
esp_idf_svc::log::EspLogger::initialize_default();
let peripherals = Peripherals::take().unwrap();
let scl = peripherals.pins.gpio22;
let sda = peripherals.pins.gpio21;
let i2c_config = Config::new()
.baudrate(KiloHertz(100).into())
.scl_enable_pullup(true)
.sda_enable_pullup(true);
let mut i2c_driver = I2cDriver::new(peripherals.i2c0, sda, scl, &i2c_config).unwrap();
let mut expander = Pcf8574::new(&mut i2c_driver, PCF857X_DEFAULT_ADDRESS);
loop {
let _ = expander.clear();
println!("All off");
thread::sleep(Duration::from_millis(1000));
let _ = expander.up_pins(&[Pin::P0]).unwrap();
println!("P0 on");
thread::sleep(Duration::from_millis(1000));
let _ = expander.up_pins(&[Pin::P1]).unwrap();
println!("P0, P1 on");
thread::sleep(Duration::from_millis(1000));
let _ = expander.up_pins(&[Pin::P2]).unwrap();
println!("P0, P1, P2 on");
thread::sleep(Duration::from_millis(1000));
let _ = expander.set_pins(&[PinState::Up(Pin::P0), PinState::Down(Pin::P1), PinState::Down(Pin::P2)]);
println!("P0 = on, P1 = off, P2 = off");
thread::sleep(Duration::from_millis(1000));
}
}
依赖项
~71KB