2022-11-15 16:12:07 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use defmt::*;
|
|
|
|
use embassy_executor::Spawner;
|
2023-07-05 20:05:34 +02:00
|
|
|
use embassy_rp::adc::{Adc, Config, InterruptHandler, Pin};
|
2023-05-15 15:21:05 +02:00
|
|
|
use embassy_rp::bind_interrupts;
|
2023-07-05 20:05:34 +02:00
|
|
|
use embassy_rp::gpio::Pull;
|
2022-11-15 16:12:07 +01:00
|
|
|
use embassy_time::{Duration, Timer};
|
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
2023-05-15 15:21:05 +02:00
|
|
|
bind_interrupts!(struct Irqs {
|
|
|
|
ADC_IRQ_FIFO => InterruptHandler;
|
|
|
|
});
|
|
|
|
|
2022-11-15 16:12:07 +01:00
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(_spawner: Spawner) {
|
|
|
|
let p = embassy_rp::init(Default::default());
|
2023-05-15 15:21:05 +02:00
|
|
|
let mut adc = Adc::new(p.ADC, Irqs, Config::default());
|
2022-11-15 16:12:07 +01:00
|
|
|
|
2023-07-05 20:05:34 +02:00
|
|
|
let mut p26 = Pin::new(p.PIN_26, Pull::None);
|
|
|
|
let mut p27 = Pin::new(p.PIN_27, Pull::None);
|
|
|
|
let mut p28 = Pin::new(p.PIN_28, Pull::None);
|
2022-11-15 16:12:07 +01:00
|
|
|
|
|
|
|
loop {
|
2023-07-05 20:05:34 +02:00
|
|
|
let level = adc.read(&mut p26).await.unwrap();
|
2022-11-15 16:12:07 +01:00
|
|
|
info!("Pin 26 ADC: {}", level);
|
2023-07-05 20:05:34 +02:00
|
|
|
let level = adc.read(&mut p27).await.unwrap();
|
2022-11-15 16:12:07 +01:00
|
|
|
info!("Pin 27 ADC: {}", level);
|
2023-07-05 20:05:34 +02:00
|
|
|
let level = adc.read(&mut p28).await.unwrap();
|
2022-11-15 16:12:07 +01:00
|
|
|
info!("Pin 28 ADC: {}", level);
|
2023-07-05 20:05:34 +02:00
|
|
|
let temp = adc.read_temperature().await.unwrap();
|
2022-12-20 02:11:39 +01:00
|
|
|
info!("Temp: {} degrees", convert_to_celsius(temp));
|
2022-11-15 16:12:07 +01:00
|
|
|
Timer::after(Duration::from_secs(1)).await;
|
|
|
|
}
|
|
|
|
}
|
2022-12-20 02:11:39 +01:00
|
|
|
|
|
|
|
fn convert_to_celsius(raw_temp: u16) -> f32 {
|
|
|
|
// According to chapter 4.9.5. Temperature Sensor in RP2040 datasheet
|
2022-12-20 07:59:49 +01:00
|
|
|
27.0 - (raw_temp as f32 * 3.3 / 4096.0 - 0.706) / 0.001721 as f32
|
|
|
|
}
|