From 7a418568ba4767766c9f17560003451b0b23f17d Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Sun, 31 Mar 2019 15:52:19 +0200 Subject: Add example measuring all channels --- examples/all_channels.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/all_channels.rs diff --git a/examples/all_channels.rs b/examples/all_channels.rs new file mode 100644 index 0000000..be016e8 --- /dev/null +++ b/examples/all_channels.rs @@ -0,0 +1,26 @@ +extern crate embedded_hal; +use embedded_hal::adc::OneShot; +extern crate linux_embedded_hal; +#[macro_use(block)] +extern crate nb; +extern crate ads1x1x; + +use ads1x1x::{channel, Ads1x1x, SlaveAddr}; +use linux_embedded_hal::I2cdev; + +fn main() { + let dev = I2cdev::new("/dev/i2c-1").unwrap(); + let address = SlaveAddr::default(); + let mut adc = Ads1x1x::new_ads1015(dev, address); + let values = [ + block!(adc.read(&mut channel::SingleA0)).unwrap(), + block!(adc.read(&mut channel::SingleA1)).unwrap(), + block!(adc.read(&mut channel::SingleA2)).unwrap(), + block!(adc.read(&mut channel::SingleA3)).unwrap(), + ]; + for (channel, value) in values.iter().enumerate() { + println!("Channel {}: {}", channel, value); + } + // get I2C device back + let _dev = adc.destroy_ads1015(); +} -- cgit v1.2.3-54-g00ecf