Expand description
Continuous ADC module Example: continuously reading value from a pin
use ::log::{info, debug};
fn main() -> anyhow::Result<()> {
use esp_idf_svc::hal::adc::{AdcContConfig, AdcContDriver, AdcMeasurement, Attenuated};
use esp_idf_svc::hal::modem::Modem;
use esp_idf_svc::hal::peripherals::Peripherals;
use esp_idf_svc::sys::EspError;
esp_idf_svc::sys::link_patches();
esp_idf_svc::log::EspLogger::initialize_default();
let peripherals = Peripherals::take()?;
let config = AdcContConfig::default();
let adc_1_channel_0 = Attenuated::db11(peripherals.pins.gpio0);
let mut adc = AdcContDriver::new(peripherals.adc1, &config, adc_1_channel_0)?;
adc.start()?;
/// Default to just read 100 measurements per each read
let mut samples = [AdcMeasurement::default(); 100];
loop {
if let Ok(num_read) = adc.read(&mut samples, 10) {
debug!("Read {} measurement.", num_read);
for index in 0..num_read {
debug!("{}", samples[index].data());
}
}
}
}
Modules§
Structs§
- Set ADC attenuation level Example: let pin = Attenuated::db11(peripherals.pins.gpio0);