embassy/examples/nrf/src/bin/saadc.rs

25 lines
767 B
Rust
Raw Normal View History

2021-09-01 23:55:20 +02:00
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use defmt::info;
use embassy_executor::executor::Spawner;
use embassy_executor::time::{Duration, Timer};
use embassy_nrf::saadc::{ChannelConfig, Config, Saadc};
2021-09-01 23:55:20 +02:00
use embassy_nrf::{interrupt, Peripherals};
2022-06-12 22:15:44 +02:00
use {defmt_rtt as _, panic_probe as _};
2021-09-01 23:55:20 +02:00
#[embassy_executor::main]
2021-09-01 23:55:20 +02:00
async fn main(_spawner: Spawner, mut p: Peripherals) {
let config = Config::default();
let channel_config = ChannelConfig::single_ended(&mut p.P0_02);
let mut saadc = Saadc::new(p.SAADC, interrupt::take!(SAADC), config, [channel_config]);
2021-09-01 23:55:20 +02:00
loop {
let mut buf = [0; 1];
saadc.sample(&mut buf).await;
info!("sample: {=i16}", &buf[0]);
2021-09-01 23:55:20 +02:00
Timer::after(Duration::from_millis(100)).await;
}
}