-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathchannel.rs
More file actions
42 lines (35 loc) · 1008 Bytes
/
channel.rs
File metadata and controls
42 lines (35 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#![no_std]
#![no_main]
use defmt::unwrap;
use embassy_executor::Spawner;
use embassy_nrf::gpio::{Level, Output, OutputDrive};
use embassy_sync::blocking_mutex::raw::ThreadModeRawMutex;
use embassy_sync::channel::Channel;
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
enum LedState {
On,
Off,
}
static CHANNEL: Channel<ThreadModeRawMutex, LedState, 1> = Channel::new();
#[embassy_executor::task]
async fn my_task() {
loop {
CHANNEL.send(LedState::On).await;
Timer::after_secs(1).await;
CHANNEL.send(LedState::Off).await;
Timer::after_secs(1).await;
}
}
#[embassy_executor::main]
async fn main(spawner: Spawner) {
let p = embassy_nrf::init(Default::default());
let mut led = Output::new(p.P0_13, Level::Low, OutputDrive::Standard);
spawner.spawn(unwrap!(my_task()));
loop {
match CHANNEL.receive().await {
LedState::On => led.set_low(),
LedState::Off => led.set_high(),
}
}
}