Crates.io | adc-interpolator |
lib.rs | adc-interpolator |
version | 0.2.0 |
source | src |
created_at | 2021-11-14 13:30:04.445589 |
updated_at | 2021-11-18 20:20:15.984865 |
description | An interpolator for analog-to-digital converters |
homepage | |
repository | https://github.com/peterstuart/adc-interpolator/ |
max_upload_size | |
id | 481720 |
size | 14,877 |
An interpolator for analog-to-digital converters.
Convert voltage readings from an ADC into meaningful values using linear interpolation.
use adc_interpolator::{AdcInterpolator, Config};
let config = Config {
max_voltage: 1000, // 1000 mV maximum voltage
precision: 12, // 12-bit precision
voltage_to_values: [
(100, 40), // 100 mV -> 40
(200, 30), // 200 mV -> 30
(300, 10), // 300 mV -> 10
],
};
let mut interpolator = AdcInterpolator::new(pin, config);
// With voltage at 150 mV, the value is 35
assert_eq!(interpolator.read(&mut adc), Ok(Some(35)));
License: MIT