Trait embedded_hal::qei::blocking::Qei [−][src]
pub trait Qei {
type Error: Debug;
type Count;
fn count(&self) -> Result<Self::Count, Self::Error>;
fn direction(&self) -> Result<Direction, Self::Error>;
}
Expand description
Quadrature encoder interface
Examples
You can use this interface to measure the speed of a motor
extern crate embedded_hal as hal;
#[macro_use(block)]
extern crate nb;
use hal::qei::blocking::Qei;
use hal::timer::nb::CountDown;
fn main() {
let mut qei: Qei1 = {
// ..
};
let mut timer: Timer6 = {
// ..
};
let before = qei.count().unwrap();
timer.start(1.s()).unwrap();
block!(timer.wait());
let after = qei.count().unwrap();
let speed = after.wrapping_sub(before);
println!("Speed: {} pulses per second", speed);
}
Associated Types
Required methods
Returns the current pulse count of the encoder