aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-07-16 16:11:37 +0000
committerGitHub <[email protected]>2022-07-16 16:11:37 +0000
commit4dc800710d2269d5baebd62ae5a62205570db365 (patch)
treeb04e87b586ec1fa2a08d9d3963302583791a78e1 /examples
parent9d388d357aefcb87677a70716e727bc91933191a (diff)
parent8979959dd15be496e74a1a670a468d4d5168f0c8 (diff)
Merge #853
853: Add embedded_hal_async support for embassy-rp r=Dirbaio a=danbev This commit adds support for embedded-hal-async to the Embassy Raspberry PI crate. Co-authored-by: Daniel Bevenius <[email protected]>
Diffstat (limited to 'examples')
-rw-r--r--examples/rp/src/bin/gpio_async.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/examples/rp/src/bin/gpio_async.rs b/examples/rp/src/bin/gpio_async.rs
new file mode 100644
index 000000000..e0f2aa961
--- /dev/null
+++ b/examples/rp/src/bin/gpio_async.rs
@@ -0,0 +1,38 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::*;
6use embassy::executor::Spawner;
7use embassy::time::{Duration, Timer};
8use embassy_rp::{gpio, Peripherals};
9use gpio::{Input, Level, Output, Pull};
10use {defmt_rtt as _, panic_probe as _};
11
12/// This example shows how async gpio can be used with a RP2040.
13///
14/// It requires an external signal to be manually triggered on PIN 16. For
15/// example, this could be accomplished using an external power source with a
16/// button so that it is possible to toggle the signal from low to high.
17///
18/// This example will begin with turning on the LED on the board and wait for a
19/// high signal on PIN 16. Once the high event/signal occurs the program will
20/// continue and turn off the LED, and then wait for 2 seconds before completing
21/// the loop and starting over again.
22#[embassy::main]
23async fn main(_spawner: Spawner, p: Peripherals) {
24 let mut led = Output::new(p.PIN_25, Level::Low);
25 let mut async_input = Input::new(p.PIN_16, Pull::None);
26
27 loop {
28 info!("wait_for_high. Turn on LED");
29 led.set_high();
30
31 async_input.wait_for_high().await;
32
33 info!("done wait_for_high. Turn off LED");
34 led.set_low();
35
36 Timer::after(Duration::from_secs(2)).await;
37 }
38}