Improve examples

This commit is contained in:
Grant Miller
2022-10-24 15:01:16 -05:00
parent 545cc9326b
commit 7a6732adcf
3 changed files with 16 additions and 12 deletions

View File

@ -16,14 +16,14 @@ async fn main(_spawner: Spawner) {
let mut adc = Adc::new(p.ADC1, &mut Delay);
let mut pin = p.PB1;
let mut vref = adc.enable_vref(&mut Delay);
let vref_sample = adc.read(&mut vref);
let mut vrefint = adc.enable_vref(&mut Delay);
let vrefint_sample = adc.read(&mut vrefint);
let convert_to_millivolts = |sample| {
// From http://www.st.com/resource/en/datasheet/CD00161566.pdf
// 5.3.4 Embedded reference voltage
const VREF_MV: u32 = 1200;
const VREFINT_MV: u32 = 1200; // mV
(u32::from(sample) * VREF_MV / u32::from(vref_sample)) as u16
(u32::from(sample) * VREFINT_MV / u32::from(vrefint_sample)) as u16
};
loop {