Prepare adc usage

This commit is contained in:
hodasemi 2022-10-28 17:33:44 +02:00
parent 99df32a0b9
commit 38e294b619

View file

@ -4,11 +4,13 @@
#![no_std]
#![no_main]
extern crate alloc;
use alloc::string::ToString;
use bsp::entry;
use defmt::*;
use defmt_rtt as _;
use embedded_hal::digital::v2::OutputPin;
use embedded_time::fixed_point::FixedPoint;
use panic_probe as _;
// Provide an alias for our BSP so we can switch targets quickly.
@ -22,8 +24,11 @@ use bsp::hal::{
sio::Sio,
usb::UsbBus,
watchdog::Watchdog,
Adc,
};
use embedded_hal::adc::OneShot;
use usb_device::{class_prelude::*, prelude::*};
use usbd_serial::SerialPort;
@ -84,6 +89,12 @@ fn main() -> ! {
.device_class(2) // from: https://www.usb.org/defined-class-codes
.build();
let mut adc = Adc::new(pac.ADC, &mut pac.RESETS);
let mut adc_pin_0 = pins.gpio26.into_floating_input();
// let mut adc_pin_1 = pins.gpio27.into_floating_input();
// let mut adc_pin_2 = pins.gpio28.into_floating_input();
let mut i = 0;
loop {
@ -98,7 +109,12 @@ fn main() -> ! {
if i == 100 {
i = 0;
serial_send(&mut serial, "test");
let adc_0_value: u16 = adc.read(&mut adc_pin_0).unwrap();
// let adc_1_value: u16 = adc.read(&mut adc_pin_1).unwrap();
// let adc_2_value: u16 = adc.read(&mut adc_pin_2).unwrap();
serial_send(&mut serial, &adc_0_value.to_string());
}
delay.delay_ms(8);