1 unstable release
Uses old Rust 2015
0.1.0 | Sep 4, 2017 |
---|
#25 in #magnetometer
28KB
470 lines
LSM303 Accelerometer and Magnetometer
This is a driver for the LSM303DLHC digital accelerometer and magnetometer.
Getting started
$ cargo run --example read
lib.rs
:
Interface to the LSM303 digital accelerometer and magnetometer.
let device = "/dev/i2c-1";
let mut accelerometer =
lsm303::Accelerometer::new(device)?;
let mut magnetometer =
lsm303::Magnetometer::new(device)?;
loop {
let accel = accelerometer.read_acceleration()?;
let mag = magnetometer.read_magnetic_field()?;
println!("Accel: ({}, {}, {}) || Mag: ({}, {}, {})",
accel.x, accel.y, accel.z,
mag.x, mag.y, mag.z);
std::thread::sleep(Duration::from_millis(100));
}
Dependencies
~5–7.5MB
~139K SLoC