examples: stm32f1: Add an example of using the ADC
This commit is contained in:
parent
f0f08f298b
commit
dafc4c54e9
29
examples/stm32f1/src/bin/adc.rs
Normal file
29
examples/stm32f1/src/bin/adc.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(type_alias_impl_trait)]
|
||||||
|
|
||||||
|
#[path = "../example_common.rs"]
|
||||||
|
mod example_common;
|
||||||
|
|
||||||
|
use embassy::executor::Spawner;
|
||||||
|
use embassy::time::Delay;
|
||||||
|
use embassy_stm32::adc::Adc;
|
||||||
|
use embassy_stm32::Peripherals;
|
||||||
|
use embassy_traits::delay::Delay as _;
|
||||||
|
use example_common::*;
|
||||||
|
|
||||||
|
#[embassy::main]
|
||||||
|
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||||
|
info!("Hello World!");
|
||||||
|
|
||||||
|
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
||||||
|
let mut pin = p.PB1;
|
||||||
|
|
||||||
|
let mut vref = adc.enable_vref(&mut Delay);
|
||||||
|
adc.calibrate(&mut vref);
|
||||||
|
loop {
|
||||||
|
let v = adc.read(&mut pin);
|
||||||
|
info!("--> {} - {} mV", v, adc.to_millivolts(v));
|
||||||
|
Delay.delay_ms(100).await;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user