Struct adc_interpolator::AdcInterpolator [−][src]
pub struct AdcInterpolator<Pin, Word, const LENGTH: usize> { /* fields omitted */ }Implementations
Returns an interpolator using the provided table.
The values in the table must be in ascending order by voltage
or this function will panic. (ie. If you are using
pair to create the pairs in the table, the voltage
parameter must increase with each pair.)
Examples
Use pair to create the pairs in table:
use adc_interpolator::{AdcInterpolator, pair};
let interpolator = AdcInterpolator::new(
pin,
[
pair::<u16>(1000, 12, 100, 40),
pair(1000, 12, 200, 30),
pair(1000, 12, 300, 10),
],
);Returns a value based on the table, using linear interpolation
between values in the table if necessary. If adc_value falls
outside the range of the table, returns Ok(None).
Examples
use adc_interpolator::{AdcInterpolator, pair};
let mut interpolator = AdcInterpolator::new(
pin,
[
pair(1000, 12, 100, 40),
pair(1000, 12, 200, 30),
pair(1000, 12, 300, 10),
],
);
// With voltage at 150 mV, the value is 35
assert_eq!(interpolator.read(&mut adc), Ok(Some(35)));