Crates.io | nxtusb |
lib.rs | nxtusb |
version | 0.2.0 |
source | src |
created_at | 2024-01-01 18:55:45.126588 |
updated_at | 2024-01-07 16:38:47.520803 |
description | USB driver for communicating with the NXT brick |
homepage | |
repository | https://github.com/bricks-rs/nxtusb |
max_upload_size | |
id | 1085492 |
size | 199,834 |
USB driver for communicating with the NXT brick. See examples for sample code.
use nxtusb::{motor::*, *};
const POWER: i8 = 80;
#[tokio::main]
async fn main() -> nxtusb::Result<()> {
let nxt = Nxt::first_usb().await?;
let _nxt2 = nxtusb::Bluetooth::wait_for_nxt().await?;
println!("Running motor A at {POWER}");
nxt.set_output_state(
OutPort::A,
POWER,
OutMode::ON | OutMode::REGULATED,
RegulationMode::Speed,
0,
RunState::Running,
RUN_FOREVER,
).await?;
std::thread::sleep(std::time::Duration::from_secs(5));
println!("Stop");
nxt.set_output_state(
OutPort::A,
0,
OutMode::IDLE,
RegulationMode::default(),
0,
RunState::Running,
RUN_FOREVER,
).await?;
let bat = nxt.get_battery_level().await?;
println!("Battery level is {bat} mV");
Ok(())
}