aboutsummaryrefslogtreecommitdiff
path: root/examples/rp235x/src/bin/gpio_async.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/rp235x/src/bin/gpio_async.rs')
-rw-r--r--examples/rp235x/src/bin/gpio_async.rs40
1 files changed, 40 insertions, 0 deletions
diff --git a/examples/rp235x/src/bin/gpio_async.rs b/examples/rp235x/src/bin/gpio_async.rs
new file mode 100644
index 000000000..b79fb2a15
--- /dev/null
+++ b/examples/rp235x/src/bin/gpio_async.rs
@@ -0,0 +1,40 @@
1//! This example shows how async gpio can be used with a RP2040.
2//!
3//! The LED on the RP Pico W board is connected differently. See wifi_blinky.rs.
4
5#![no_std]
6#![no_main]
7
8use defmt::*;
9use embassy_executor::Spawner;
10use embassy_rp::gpio;
11use embassy_time::Timer;
12use gpio::{Input, Level, Output, Pull};
13use {defmt_rtt as _, panic_probe as _};
14
15/// It requires an external signal to be manually triggered on PIN 16. For
16/// example, this could be accomplished using an external power source with a
17/// button so that it is possible to toggle the signal from low to high.
18///
19/// This example will begin with turning on the LED on the board and wait for a
20/// high signal on PIN 16. Once the high event/signal occurs the program will
21/// continue and turn off the LED, and then wait for 2 seconds before completing
22/// the loop and starting over again.
23#[embassy_executor::main]
24async fn main(_spawner: Spawner) {
25 let p = embassy_rp::init(Default::default());
26 let mut led = Output::new(p.PIN_25, Level::Low);
27 let mut async_input = Input::new(p.PIN_16, Pull::None);
28
29 loop {
30 info!("wait_for_high. Turn on LED");
31 led.set_high();
32
33 async_input.wait_for_high().await;
34
35 info!("done wait_for_high. Turn off LED");
36 led.set_low();
37
38 Timer::after_secs(2).await;
39 }
40}