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

Enumeration of Qei errors

The type of the value returned by count

Required methods

Returns the current pulse count of the encoder

Returns the count direction

Implementations on Foreign Types

Implementors