Skip to content

Commit

Permalink
modernize code snippet in home.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Jan 22, 2024
1 parent e4c57f4 commit e7c7465
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,31 @@ <h2>Rust + async ❤️ embedded</h2>
{% filter markdown%}
```rust
use defmt::info;
use embassy::executor::Spawner;
use embassy::time::{Duration, Timer};
use embassy_executor::Spawner;
use embassy_nrf::gpio::{AnyPin, Input, Level, Output, OutputDrive, Pin, Pull};
use embassy_nrf::Peripherals;
use embassy_time::{Duration, Timer};

// Declare async tasks
#[embassy::task]
#[embassy_executor::task]
async fn blink(pin: AnyPin) {
let mut led = Output::new(pin, Level::Low, OutputDrive::Standard);

loop {
// Timekeeping is globally available, no need to mess with hardware timers.
led.set_high();
Timer::after(Duration::from_millis(150)).await;
Timer::after_millis(150).await;
led.set_low();
Timer::after(Duration::from_millis(150)).await;
Timer::after_millis(150).await;
}
}

// Main is itself an async task as well.
#[embassy::main]
async fn main(spawner: Spawner, p: Peripherals) {
#[embassy_executor::main]
async fn main(spawner: Spawner) {
// Initialize the embassy-nrf HAL.
let p = embassy_nrf::init(Default::default());

// Spawned tasks run in the background, concurrently.
spawner.spawn(blink(p.P0_13.degrade())).unwrap();

Expand Down

0 comments on commit e7c7465

Please sign in to comment.