aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/stm32h7/src/bin/rng.rs35
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"]
8mod example_common;
9use embassy::executor::Spawner;
10use embassy::time::{Duration, Timer};
11use embassy_stm32::gpio::{Level, Output, Speed};
12use embassy_stm32::Peripherals;
13use embedded_hal::digital::v2::OutputPin;
14use example_common::*;
15use embassy_stm32::rng::Random;
16use embassy::traits::rng::Rng;
17
18#[embassy::main]
19async 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}