diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32h7/src/bin/rng.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/stm32h7/src/bin/rng.rs b/examples/stm32h7/src/bin/rng.rs new file mode 100644 index 000000000..48aad26b1 --- /dev/null +++ b/examples/stm32h7/src/bin/rng.rs | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | #![allow(incomplete_features)] | ||
| 6 | |||
| 7 | #[path = "../example_common.rs"] | ||
| 8 | mod example_common; | ||
| 9 | use embassy::executor::Spawner; | ||
| 10 | use embassy::time::{Duration, Timer}; | ||
| 11 | use embassy_stm32::gpio::{Level, Output, Speed}; | ||
| 12 | use embassy_stm32::Peripherals; | ||
| 13 | use embedded_hal::digital::v2::OutputPin; | ||
| 14 | use example_common::*; | ||
| 15 | use embassy_stm32::rng::Random; | ||
| 16 | use embassy::traits::rng::Rng; | ||
| 17 | |||
| 18 | #[embassy::main] | ||
| 19 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 20 | info!("Hello World!"); | ||
| 21 | |||
| 22 | let mut led = Output::new(p.PB14, Level::High, Speed::Low); | ||
| 23 | |||
| 24 | let mut rng = Random::new(p.RNG); | ||
| 25 | |||
| 26 | loop { | ||
| 27 | info!("high {}", unwrap!(rng.next(16).await) ); | ||
| 28 | unwrap!(led.set_high()); | ||
| 29 | Timer::after(Duration::from_millis(500)).await; | ||
| 30 | |||
| 31 | info!("low {}", unwrap!(rng.next(16).await) ); | ||
| 32 | unwrap!(led.set_low()); | ||
| 33 | Timer::after(Duration::from_millis(500)).await; | ||
| 34 | } | ||
| 35 | } | ||
