2020-11-08 18:00:08 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
2022-04-02 02:35:06 +00:00
|
|
|
use defmt::{info, unwrap};
|
2022-08-17 21:40:16 +00:00
|
|
|
use embassy_executor::Spawner;
|
2024-01-22 20:19:18 +00:00
|
|
|
use embassy_nrf::gpio::{Input, Pull};
|
2022-06-12 20:15:44 +00:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2022-07-29 19:58:35 +00:00
|
|
|
#[embassy_executor::task(pool_size = 4)]
|
2024-01-22 20:19:18 +00:00
|
|
|
async fn button_task(n: usize, mut pin: Input<'static>) {
|
2020-11-08 18:00:08 +00:00
|
|
|
loop {
|
2021-04-14 14:25:54 +00:00
|
|
|
pin.wait_for_low().await;
|
2020-11-08 18:00:08 +00:00
|
|
|
info!("Button {:?} pressed!", n);
|
2021-04-14 14:25:54 +00:00
|
|
|
pin.wait_for_high().await;
|
2020-11-08 18:00:08 +00:00
|
|
|
info!("Button {:?} released!", n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:58:35 +00:00
|
|
|
#[embassy_executor::main]
|
2022-08-17 16:49:55 +00:00
|
|
|
async fn main(spawner: Spawner) {
|
|
|
|
let p = embassy_nrf::init(Default::default());
|
2021-05-11 23:01:08 +00:00
|
|
|
info!("Starting!");
|
2020-11-08 18:00:08 +00:00
|
|
|
|
2024-01-22 20:19:18 +00:00
|
|
|
let btn1 = Input::new(p.P0_11, Pull::Up);
|
|
|
|
let btn2 = Input::new(p.P0_12, Pull::Up);
|
|
|
|
let btn3 = Input::new(p.P0_24, Pull::Up);
|
|
|
|
let btn4 = Input::new(p.P0_25, Pull::Up);
|
2021-03-29 01:09:51 +00:00
|
|
|
|
2021-07-31 15:51:40 +00:00
|
|
|
unwrap!(spawner.spawn(button_task(1, btn1)));
|
|
|
|
unwrap!(spawner.spawn(button_task(2, btn2)));
|
|
|
|
unwrap!(spawner.spawn(button_task(3, btn3)));
|
|
|
|
unwrap!(spawner.spawn(button_task(4, btn4)));
|
2020-11-08 18:00:08 +00:00
|
|
|
}
|