gp2y0e02b

Crates.iogp2y0e02b
lib.rsgp2y0e02b
version0.2.1
sourcesrc
created_at2022-06-24 07:53:05.676428
updated_at2022-09-03 15:17:01.958797
descriptionA rust driver for the GP2Y0E02B (SHARP I2C Distance Measuring Sensor, 4-50cm)
homepage
repositoryhttps://github.com/lucazulian/gp2y0e02b
max_upload_size
id612260
size15,832
luca zulian (lucazulian)

documentation

README

gp2y0e02b

no_std driver for GP2Y0E02B (SHARP I2C Distance Measuring Sensor, 4-50cm)

Build Status crates.io Docs

Basic usage

Include this library as a dependency in your Cargo.toml:

[dependencies.gp2y0e02b]
version = "<version>"

Use embedded-hal implementation to get I2C handle and then create gp2y0e02b handle.

extern crate gp2y0e02b;

match gp2y0e02b::GP2Y0E02B::new(i2c) {
    Ok(mut u) => {
        loop {
            match u.read_distance() {
                Ok(val) => {
                    println!("{:#?}", val).unwrap();
                }
                _ => {
                    println!("Not ready").unwrap();
                }
            }
        }
    }
    Err(gp2y0e02b::GP2Y0E02B::Error::BusError(error)) => {
        println!("{:#?}", error).unwrap();
        panic!();
    }
    _ => {
        panic!();
    }
};

License

MIT license

Commit count: 8

cargo fmt