From 6b158ba94aa096619e218f0302eec35baeebaf12 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 1 Sep 2021 23:55:20 +0200 Subject: [PATCH] nrf/saadc: add example --- examples/nrf/src/bin/saadc.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/nrf/src/bin/saadc.rs diff --git a/examples/nrf/src/bin/saadc.rs b/examples/nrf/src/bin/saadc.rs new file mode 100644 index 000000000..f96cf2903 --- /dev/null +++ b/examples/nrf/src/bin/saadc.rs @@ -0,0 +1,25 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] +#![allow(incomplete_features)] + +#[path = "../example_common.rs"] +mod example_common; +use defmt::panic; +use embassy::executor::Spawner; +use embassy::time::{Duration, Timer}; +use embassy_nrf::saadc::{Config, OneShot, Sample}; +use embassy_nrf::{interrupt, Peripherals}; +use example_common::*; + +#[embassy::main] +async fn main(_spawner: Spawner, mut p: Peripherals) { + let config = Config::default(); + let mut saadc = OneShot::new(p.SAADC, interrupt::take!(SAADC), config); + + loop { + let sample = saadc.sample(&mut p.P0_02).await; + info!("sample: {=i16}", sample); + Timer::after(Duration::from_millis(100)).await; + } +}