diff options
Diffstat (limited to 'examples/rp/src/bin/button.rs')
| -rw-r--r-- | examples/rp/src/bin/button.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/rp/src/bin/button.rs b/examples/rp/src/bin/button.rs new file mode 100644 index 000000000..c4d942ff5 --- /dev/null +++ b/examples/rp/src/bin/button.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(asm)] | ||
| 4 | #![feature(min_type_alias_impl_trait)] | ||
| 5 | #![feature(impl_trait_in_bindings)] | ||
| 6 | #![feature(type_alias_impl_trait)] | ||
| 7 | #![allow(incomplete_features)] | ||
| 8 | |||
| 9 | #[path = "../example_common.rs"] | ||
| 10 | mod example_common; | ||
| 11 | |||
| 12 | use embassy::executor::Spawner; | ||
| 13 | use embassy_rp::gpio::{Input, Level, Output, Pull}; | ||
| 14 | use embassy_rp::Peripherals; | ||
| 15 | use embedded_hal::digital::v2::{InputPin, OutputPin}; | ||
| 16 | |||
| 17 | #[embassy::main] | ||
| 18 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 19 | let button = Input::new(p.PIN_28, Pull::Up); | ||
| 20 | let mut led = Output::new(p.PIN_25, Level::Low); | ||
| 21 | |||
| 22 | loop { | ||
| 23 | if button.is_high().unwrap() { | ||
| 24 | led.set_high().unwrap(); | ||
| 25 | } else { | ||
| 26 | led.set_low().unwrap(); | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
