Delay

embedded-hal provides the delay trait for generating precise delays. The HAL provides an implementation which you can access by using the SYST in the Peripherals for the Delay struct.

Try using it to blink the led and check if it really delays the right amount of time.

Driver crate

We can now use other driver crates to add more functionality. For this example, we're using the embedded-morse crate to output morse messages over the led.

Add the crate to the Cargo.toml to the [dependencies] section and make an instance in the src/main.rs:


#![allow(unused_variables)]
fn main() {
let mut delay = lpc8xx_hal::delay::Delay::new(p.SYST);
// the last argument inverts the output, since the led is active-low
let mut morse = embedded_morse::Morse::new_default(delay.clone(), led, true);
}

Now output something using output_str.

The embedded-morse driver uses only traits from embedded-hal. Because of that, it will work on a large swath of microcontrollers, without needing to modify it.