summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorDiego Barrios Romero <eldruin@gmail.com>2018-11-17 07:51:26 +0100
committerDiego Barrios Romero <eldruin@gmail.com>2018-11-17 07:51:26 +0100
commit0ed9482e5935300fe22f462c9fb7c417418a7181 (patch)
tree2660594e7fe58cb3c90ee178496fc01bd5fe74c1 /README.md
parent9d005392012213dc12527b913a9ea4f72b97368c (diff)
downloadads1x1x-async-0ed9482e5935300fe22f462c9fb7c417418a7181.tar.gz
ads1x1x-async-0ed9482e5935300fe22f462c9fb7c417418a7181.tar.xz
ads1x1x-async-0ed9482e5935300fe22f462c9fb7c417418a7181.zip
Add usage example to readme
Diffstat (limited to 'README.md')
-rw-r--r--README.md28
1 files changed, 28 insertions, 0 deletions
diff --git a/README.md b/README.md
index 81d1a48..615e9aa 100644
--- a/README.md
+++ b/README.md
@@ -61,6 +61,34 @@ Datasheets:
- [ADS111x](http://www.ti.com/lit/ds/symlink/ads1115.pdf)
- [ADS1118](http://www.ti.com/lit/ds/symlink/ads1118.pdf)
+## Usage
+
+To use this driver, import this crate and an `embedded_hal` implementation,
+then instantiate the appropriate device.
+In the following examples an instance of the device ADS1013 will be created
+as an example. Other devices can be created with similar methods like:
+`Ads1x1x::new_ads1114(...)`.
+
+```rust
+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
+}
+```
+
## License
Licensed under either of