nucleo-l053r8/examples/blinky-press.rs

36 lines
841 B
Rust
Executable file

#![no_main]
#![no_std]
extern crate panic_halt;
use cortex_m_rt::entry;
use hal::{pac, prelude::*, rcc::Config};
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let cp = cortex_m::Peripherals::take().unwrap();
// Configure the clock.
let mut rcc = dp.RCC.freeze(Config::hsi16());
let gpioa = dp.GPIOA.split(&mut rcc);
let gpioc = dp.GPIOC.split(&mut rcc);
// Configure PA5 as output.
let mut led = gpioa.pa5.into_push_pull_output();
let mut button = gpioc.pc13.into_pull_down_input();
// Get the delay provider.
let mut delay = cp.SYST.delay(rcc.clocks);
loop {
if button.is_low().expect("button.is_low failed") {
led.set_high().unwrap();
} else {
led.set_low().unwrap();
}
delay.delay_ms(10_u16);
}
}