diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/mimxrt6/src/bin/button.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/mimxrt6/src/bin/button.rs b/examples/mimxrt6/src/bin/button.rs new file mode 100644 index 000000000..efb7f14af --- /dev/null +++ b/examples/mimxrt6/src/bin/button.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | use defmt::info; | ||
| 5 | use embassy_executor::Spawner; | ||
| 6 | use embassy_futures::select::{select, Either}; | ||
| 7 | use embassy_imxrt::gpio; | ||
| 8 | use {defmt_rtt as _, embassy_imxrt_examples as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async fn main(_spawner: Spawner) { | ||
| 12 | let p = embassy_imxrt::init(Default::default()); | ||
| 13 | |||
| 14 | let mut user1 = gpio::Input::new(p.PIO1_1, gpio::Pull::None, gpio::Inverter::Disabled); | ||
| 15 | let mut user2 = gpio::Input::new(p.PIO0_10, gpio::Pull::None, gpio::Inverter::Disabled); | ||
| 16 | |||
| 17 | loop { | ||
| 18 | let res = select(user1.wait_for_falling_edge(), user2.wait_for_falling_edge()).await; | ||
| 19 | |||
| 20 | match res { | ||
| 21 | Either::First(()) => { | ||
| 22 | info!("Button `USER1' pressed"); | ||
| 23 | } | ||
| 24 | Either::Second(()) => { | ||
| 25 | info!("Button `USER2' pressed"); | ||
| 26 | } | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
