Trait cortex_m::prelude::_embedded_hal_Qei

source ·
pub trait _embedded_hal_Qei {
    type Count;

    // Required methods
    fn count(&self) -> Self::Count;
    fn direction(&self) -> Direction;
}
Expand description

Quadrature encoder interface

This trait is available if embedded-hal is built with the "unproven" feature.

§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.count();
    timer.start(1.s());
    block!(timer.wait());
    let after = qei.count();

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

Required Associated Types§

source

type Count

The type of the value returned by count

Required Methods§

source

fn count(&self) -> Self::Count

Returns the current pulse count of the encoder

source

fn direction(&self) -> Direction

Returns the count direction

Implementors§