# Qei in embedded_hal::qei - Rust
Quadrature encoder interface
Keywords: rust, rustlang, rust-lang, Qei

# Trait embedded_hal::qei::Qei

source · [−]

    pub trait Qei {
        type Error;
        type Count;
        fn try_count(&self) -> Result<Self::Count, Self::Error>;
        fn try_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::prelude::*;

    fn main() {
        let mut qei: Qei1 = {
            // ..
        };
        let mut timer: Timer6 = {
            // ..
        };

        let before = qei.try_count().unwrap();
        timer.try_start(1.s()).unwrap();
        block!(timer.try_wait());
        let after = qei.try_count().unwrap();

        let speed = after.wrapping_sub(before);
        println!("Speed: {} pulses per second", speed);
    }

## Associated Types

source

#### type Error

Enumeration of `Qei` errors

source

#### type Count

The type of the value returned by `count`

## Required methods

source

#### fn try_count(&self) -> Result<Self::Count, Self::Error>

Returns the current pulse count of the encoder

source

#### fn try_direction(&self) -> Result<Direction, Self::Error>

Returns the count direction

## Implementors