Move blinky and temp/rh measurement into separate binaries
This commit is contained in:
24
src/bin/blinky.rs
Normal file
24
src/bin/blinky.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::gpio::{Level, Output, OutputDrive};
|
||||
use embassy_time::Timer;
|
||||
use nrf_softdevice::{raw, Softdevice};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let mut led = Output::new(p.P0_20, Level::Low, OutputDrive::Standard);
|
||||
|
||||
info!("Starting blinky");
|
||||
|
||||
loop {
|
||||
led.set_high();
|
||||
Timer::after_millis(300).await;
|
||||
led.set_low();
|
||||
Timer::after_millis(300).await;
|
||||
}
|
||||
}
|
||||
45
src/bin/temp_rh_measurement.rs
Normal file
45
src/bin/temp_rh_measurement.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use embassy_time::Timer;
|
||||
use nrf_softdevice::{raw, Softdevice};
|
||||
|
||||
use defmt::*;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::twim::{self, Twim};
|
||||
use embassy_nrf::{bind_interrupts, peripherals};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
const ADDRESS: u8 = 0x44;
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
TWIM0_TWIS0_TWI0 => twim::InterruptHandler<peripherals::TWI0>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
|
||||
info!("Initializing TWI...");
|
||||
|
||||
let config = twim::Config::default();
|
||||
let mut twi = Twim::new(p.TWI0, Irqs, p.P0_14, p.P0_13, config);
|
||||
|
||||
loop {
|
||||
unwrap!(twi.blocking_write(ADDRESS, &mut [0xFD]));
|
||||
|
||||
Timer::after_millis(10).await;
|
||||
|
||||
let mut buf = [0u8; 6];
|
||||
unwrap!(twi.blocking_read(ADDRESS, &mut buf));
|
||||
|
||||
let temp_int = u16::from_be_bytes([buf[0], buf[1]]);
|
||||
let temp_float: f32 = -45f32 + 175f32 * (temp_int as f32 / (2u32.pow(16) - 1) as f32);
|
||||
|
||||
let rh_int = u16::from_be_bytes([buf[3], buf[4]]);
|
||||
let rh_float: f32 = -6f32 + 125f32 * (rh_int as f32 / (2u32.pow(16) - 1) as f32);
|
||||
println!("{}\t{}", temp_float, rh_float);
|
||||
|
||||
Timer::after_millis(50).await;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user