Expand description
§nxt
USB & Bluetooth driver for communicating with the NXT brick. See examples for sample code.
§Example
use nxt::{motor::*, *};
const POWER: i8 = 80;
#[tokio::main]
async fn main() -> nxt::Result<()> {
let nxt = Nxt::first_usb().await?;
let _nxt2 = nxt::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(())
}
Modules§
- motor
- Types and functionality related to motor functions
- sensor
- Types and functionality related to sensor & input functions
- system
- Types and functionality related to system functions
Structs§
- Bluetooth
- A handle to an NXT brick over Bluetooth
- Nxt
- Main interface to this crate, an
NXT
represents a connection to a programmable brick. - Usb
- A handle to an NXT brick over USB
Enums§
Constants§
- DISPLAY_
DATA_ LEN - Total number of LCD pixels
- DISPLAY_
HEIGHT - Height of NXT LCD screen in pixels
- DISPLAY_
WIDTH - Width of NXT LCD screen in pixels
- MAX_
INBOX_ ID - Largest inbox ID for inter-brick messaging
- MAX_
MESSAGE_ LEN - Maximum length of a USB message