diff options
| author | Henrik Alsér <[email protected]> | 2022-05-07 00:46:36 +0200 |
|---|---|---|
| committer | Henrik Alsér <[email protected]> | 2022-05-07 00:46:36 +0200 |
| commit | 840bb2952e68465ff5e58846db5a4f1ced76834b (patch) | |
| tree | 296f49f2ee68a0d5ba558fcad8bacc86315457fc /examples/nrf/src | |
| parent | f7af9a549f165419f4fa85c82b42a3e5b54d417e (diff) | |
Add qdec module
Diffstat (limited to 'examples/nrf/src')
| -rw-r--r-- | examples/nrf/src/bin/qdec.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/examples/nrf/src/bin/qdec.rs b/examples/nrf/src/bin/qdec.rs new file mode 100644 index 000000000..9c670cea0 --- /dev/null +++ b/examples/nrf/src/bin/qdec.rs | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::info; | ||
| 6 | use embassy::executor::Spawner; | ||
| 7 | use embassy_nrf::{ | ||
| 8 | interrupt, | ||
| 9 | qdec::{self, Qdec}, | ||
| 10 | Peripherals, | ||
| 11 | }; | ||
| 12 | |||
| 13 | use defmt_rtt as _; // global logger | ||
| 14 | use panic_probe as _; | ||
| 15 | |||
| 16 | #[embassy::main] | ||
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 18 | let irq = interrupt::take!(QDEC); | ||
| 19 | let config = qdec::Config::default(); | ||
| 20 | let mut rotary = Qdec::new(p.QDEC, irq, p.P1_13, p.P0_12, config); | ||
| 21 | // let mut rotary = Qdec::new(p.QDEC, irq, p.P0_31, p.P0_30, config); | ||
| 22 | |||
| 23 | info!("Turn rotary encoder!"); | ||
| 24 | let mut value = 0; | ||
| 25 | loop { | ||
| 26 | value += rotary.read().await; | ||
| 27 | info!("Value: {}", value); | ||
| 28 | } | ||
| 29 | } | ||
