Jesse Braham a586cb311e
Rename the ADC constructor to new, make it infallible (#1133)
* Rename the ADC constructor to `new`, make it infallible

* Update `CHANGELOG.md`
2024-02-01 11:51:05 +00:00

40 lines
1.1 KiB
Rust

//! Connect a potentiometer to PIN2 and see the read values change when
//! rotating the shaft. Alternatively you could also connect the PIN to GND or
//! 3V3 to see the maximum and minimum raw values read.
#![no_std]
#![no_main]
use esp32c3_hal::{
adc::{AdcConfig, Attenuation, ADC},
clock::ClockControl,
gpio::IO,
peripherals::{Peripherals, ADC1},
prelude::*,
Delay,
};
use esp_backtrace as _;
use esp_println::println;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let system = peripherals.SYSTEM.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
// Create ADC instances
let mut adc1_config = AdcConfig::new();
let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB);
let mut adc1 = ADC::<ADC1>::new(peripherals.ADC1, adc1_config);
let mut delay = Delay::new(&clocks);
loop {
let pin_value = nb::block!(adc1.read(&mut pin)).unwrap();
println!("PIN2 ADC reading = {}", pin_value);
delay.delay_ms(1500u32);
}
}