-
Notifications
You must be signed in to change notification settings - Fork 0
/
blinky.rs
64 lines (48 loc) · 1.35 KB
/
blinky.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#![no_main]
#![no_std]
use cortex_m_rt::entry;
use nrf52_hal_example::nb::block;
use panic_halt;
use nrf52_hal_example::nrf52832_hal::{gpio::Level, prelude::*, timer::Timer};
use nrf52_hal_example::blink;
use nrf52_hal_example::nrf52832_pac::Peripherals;
use nrf52_hal_example::Pins;
#[entry]
fn main() -> ! {
let p = Peripherals::take().unwrap();
let pins = Pins::new(p.P0.split());
let mut led1 = pins.led1.into_push_pull_output(Level::Low);
let mut led2 = pins.led2.into_push_pull_output(Level::Low);
let mut led3 = pins.led3.into_push_pull_output(Level::Low);
let mut led4 = pins.led4.into_push_pull_output(Level::Low);
let mut timer = p.TIMER0.constrain();
loop {
led1.set_low();
led2.set_high();
led3.set_high();
led4.set_high();
delay(&mut timer, blink);
led1.set_high();
led2.set_low();
led3.set_high();
led4.set_high();
delay(&mut timer, blink);
led1.set_high();
led2.set_high();
led3.set_low();
led4.set_high();
delay(&mut timer, blink);
led1.set_high();
led2.set_high();
led3.set_high();
led4.set_low();
delay(&mut timer, blink);
}
}
fn delay<T>(timer: &mut Timer<T>, cycles: u32)
where
T: TimerExt,
{
timer.start(cycles);
block!(timer.wait());
}