[][src]Trait bl602_hal::prelude::_embedded_hal_Qei

pub trait _embedded_hal_Qei {
    type Error;
    type Count;
    fn try_count(&self) -> Result<Self::Count, Self::Error>;
fn try_direction(&self) -> Result<Direction, Self::Error>; }

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

type Error

Enumeration of Qei errors

type Count

The type of the value returned by count

Loading content...

Required methods

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

Returns the current pulse count of the encoder

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

Returns the count direction

Loading content...

Implementors

Loading content...