2020-11-08 19:00:08 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2022-04-02 04:35:06 +02:00
|
|
|
use defmt::{info, unwrap};
|
2021-03-29 02:47:10 +02:00
|
|
|
use embassy::executor::Spawner;
|
2021-03-21 21:03:02 +01:00
|
|
|
use embassy_nrf::gpio::{AnyPin, Input, Pin as _, Pull};
|
2021-03-21 21:58:59 +01:00
|
|
|
use embassy_nrf::Peripherals;
|
2022-04-02 04:35:06 +02:00
|
|
|
|
|
|
|
use defmt_rtt as _; // global logger
|
|
|
|
use panic_probe as _;
|
2020-11-08 19:00:08 +01:00
|
|
|
|
2021-03-29 03:09:51 +02:00
|
|
|
#[embassy::task(pool_size = 4)]
|
2021-12-14 13:23:40 +01:00
|
|
|
async fn button_task(n: usize, mut pin: Input<'static, AnyPin>) {
|
2020-11-08 19:00:08 +01:00
|
|
|
loop {
|
2021-04-14 16:25:54 +02:00
|
|
|
pin.wait_for_low().await;
|
2020-11-08 19:00:08 +01:00
|
|
|
info!("Button {:?} pressed!", n);
|
2021-04-14 16:25:54 +02:00
|
|
|
pin.wait_for_high().await;
|
2020-11-08 19:00:08 +01:00
|
|
|
info!("Button {:?} released!", n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 02:47:10 +02:00
|
|
|
#[embassy::main]
|
2021-05-12 01:57:01 +02:00
|
|
|
async fn main(spawner: Spawner, p: Peripherals) {
|
2021-05-12 01:01:08 +02:00
|
|
|
info!("Starting!");
|
2020-11-08 19:00:08 +01:00
|
|
|
|
2021-12-14 13:23:40 +01:00
|
|
|
let btn1 = Input::new(p.P0_11.degrade(), Pull::Up);
|
|
|
|
let btn2 = Input::new(p.P0_12.degrade(), Pull::Up);
|
|
|
|
let btn3 = Input::new(p.P0_24.degrade(), Pull::Up);
|
|
|
|
let btn4 = Input::new(p.P0_25.degrade(), Pull::Up);
|
2021-03-29 03:09:51 +02:00
|
|
|
|
2021-07-31 17:51:40 +02: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 19:00:08 +01:00
|
|
|
}
|