diff options
author | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-17 07:46:56 +0100 |
---|---|---|
committer | Diego Barrios Romero <eldruin@gmail.com> | 2018-11-17 07:46:56 +0100 |
commit | 3301638b091780c73fdbfba05be051507cd5b382 (patch) | |
tree | 67b15c016c5da5ba43e6442b0e78f5f05eefcb49 /src/lib.rs | |
parent | f2241aae6c2b7060eb694f82d835472b144d872e (diff) | |
download | ads1x1x-async-3301638b091780c73fdbfba05be051507cd5b382.tar.gz ads1x1x-async-3301638b091780c73fdbfba05be051507cd5b382.tar.xz ads1x1x-async-3301638b091780c73fdbfba05be051507cd5b382.zip |
Add usage examples
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 62 |
1 files changed, 59 insertions, 3 deletions
@@ -83,11 +83,11 @@ //! # fn main() { //! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap(); //! let address = SlaveAddr::default(); -//! let rtc = Ads1x1x::new_ads1013(dev, address); +//! let adc = Ads1x1x::new_ads1013(dev, address); //! // do something... //! //! // get the I2C device back -//! let dev = rtc.destroy_ads1013(); +//! let dev = adc.destroy_ads1013(); //! # } //! ``` //! @@ -102,7 +102,63 @@ //! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap(); //! let (a1, a0) = (true, false); //! let address = SlaveAddr::Alternative(a1, a0); -//! let rtc = Ads1x1x::new_ads1013(dev, address); +//! let adc = Ads1x1x::new_ads1013(dev, address); +//! # } +//! ``` +//! +//! ### Make a one-shot measurement +//! ```no_run +//! extern crate embedded_hal; +//! use embedded_hal::adc::OneShot; +//! extern crate linux_embedded_hal; +//! #[macro_use(block)] +//! extern crate nb; +//! extern crate ads1x1x; +//! +//! use linux_embedded_hal::I2cdev; +//! use ads1x1x::{ Ads1x1x, SlaveAddr, channel }; +//! +//! # fn main() { +//! let dev = I2cdev::new("/dev/i2c-1").unwrap(); +//! let mut adc = Ads1x1x::new_ads1013(dev, SlaveAddr::default()); +//! let measurement = block!(adc.read(&mut channel::DifferentialA0A1)).unwrap(); +//! println!("Measurement: {}", measurement); +//! let _dev = adc.destroy_ads1013(); // get I2C device back +//! # } +//! ``` +//! +//! ### Change into continuous conversion mode +//! +//! ```no_run +//! extern crate linux_embedded_hal as hal; +//! extern crate ads1x1x; +//! use ads1x1x::{ Ads1x1x, SlaveAddr }; +//! +//! # fn main() { +//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap(); +//! let address = SlaveAddr::default(); +//! let adc = Ads1x1x::new_ads1013(dev, address); +//! let mut adc = adc.into_continuous().unwrap(); +//! # } +//! ``` +//! +//! ### Set the data rate +//! For 12-bit devices, the available data rates are given by `DataRate12Bit`. +//! For 16-bit devices, the available data rates are given by `DataRate16Bit`. +//! +//! ```no_run +//! extern crate linux_embedded_hal as hal; +//! extern crate ads1x1x; +//! use ads1x1x::{ Ads1x1x, SlaveAddr, DataRate16Bit }; +//! +//! # fn main() { +//! let dev = hal::I2cdev::new("/dev/i2c-1").unwrap(); +//! let address = SlaveAddr::default(); +//! let mut adc = Ads1x1x::new_ads1115(dev, address); +//! adc.set_data_rate(DataRate16Bit::Sps860).unwrap(); +//! # } +//! ``` +//! //! # } //! ``` |