Skip to content

Commit

Permalink
Add example of delay helper function.
Browse files Browse the repository at this point in the history
  • Loading branch information
armandas committed Apr 1, 2024
1 parent 18b58b2 commit 47ab236
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions examples/atmega2560/src/bin/atmega2560-blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,31 @@
#![no_main]

use panic_halt as _;
use atmega_hal::delay::Delay;
use embedded_hal::delay::DelayNs;

// Define core clock. This can be used in the rest of the project.
type CoreClock = atmega_hal::clock::MHz16;
type Delay = atmega_hal::delay::Delay<crate::CoreClock>;

// Below are examples of a delay helper functions
fn delay_ms(ms: u16) {
Delay::new().delay_ms(u32::from(ms))
}

#[allow(dead_code)]
fn delay_us(us: u32) {
Delay::new().delay_us(us)
}

#[avr_device::entry]
fn main() -> ! {
let dp = atmega_hal::Peripherals::take().unwrap();
let pins = atmega_hal::pins!(dp);
let mut delay = Delay::<crate::CoreClock>::new();

let mut led = pins.pb7.into_output();

loop {
led.toggle();
delay.delay_ms(1000);
delay_ms(1000);
}
}

0 comments on commit 47ab236

Please sign in to comment.