Struct libbeaglebone::adc::ADC
[−]
[src]
pub struct ADC { /* fields omitted */ }
Represents a pin configured as an ADC.
Methods
impl ADC
[src]
fn new(m_adc_num: u8, m_scaling_factor: f32) -> ADC
Creates a new ADC object.
fn read(&self) -> Result<u32>
Reads the raw voltage of the ADC.
Examples
use libbeaglebone::adc::ADC; // Create a new ADC pin using ADC #0 and no scaling factor. let mut sensor = ADC::new(0, 0.0); // Read the ADC value. sensor.read().unwrap();
fn scaled_read(&self) -> Result<f32>
Reads the raw voltage of the ADC and applies a scaling factor to it.
Useful for converting from a raw voltage to the actual unit measured by a sensor. For example, raw voltage -> degrees Celsius for a temperature sensor might have a scaling factor of 0.0122.
Examples
use libbeaglebone::adc::ADC; // Create a new ADC pin using ADC #6 and a scaling factor of 0.0122. let mut sensor = ADC::new(6, 0.0122); // Read the ADC value and scale it to degrees Celsius. sensor.scaled_read().unwrap();