Skip to content

Commit

Permalink
examples: Add random example
Browse files Browse the repository at this point in the history
  • Loading branch information
chrysn committed Apr 11, 2024
1 parent a8b8f08 commit d94b2f4
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
45 changes: 45 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/laze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ subdirs:
- embassy-usb-keyboard
- hello-world
- minimal
- random
- threading
15 changes: 15 additions & 0 deletions examples/random/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "random"
version = "0.1.0"
authors.workspace = true
edition.workspace = true
publish = false

[dependencies]
# not enabling riot-rs/hwrng even though it's currently needed -- laze takes
# care of that.
riot-rs = { path = "../../src/riot-rs", features = ["threading"] }
riot-rs-boards = { path = "../../src/riot-rs-boards" }

riot-rs-random = { version = "0.1.0", path = "../../src/riot-rs-random" }
rand = { version = "0.8.5", default-features = false }
17 changes: 17 additions & 0 deletions examples/random/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# random

## About

This application performs a very important role in physical computing:
It produces randomness in the form of a dice roll (values 1 to 6, inclusive).
It prints out a single random value via the debug console.

## How to run

In this folder, run

laze build -b nrf52840dk run

This will print different values most of the time on all boards it can be built
on. If there is no way to get startup entropy on a board, the example can not
be built.
5 changes: 5 additions & 0 deletions examples/random/laze.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apps:
- name: random
selects:
- ?release
- rng
19 changes: 19 additions & 0 deletions examples/random/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![no_main]
#![no_std]
#![feature(type_alias_impl_trait)]
#![feature(used_with_arg)]

use riot_rs::debug::{println};

#[riot_rs::thread(autostart)]
fn main() {
use rand::Rng as _;
let mut rng = riot_rs_random::get_rng();

let value = rng.gen_range(1..=6);

println!(
"The random value of this round is {}.",
value
);
}

0 comments on commit d94b2f4

Please sign in to comment.