Skip to content

Commit 8ee50c1

Browse files
committed
Moved the 05-led-roulette it-blinks examples to project examples
1 parent 93aee67 commit 8ee50c1

File tree

3 files changed

+71
-68
lines changed

3 files changed

+71
-68
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#![deny(unsafe_code)]
2+
#![no_main]
3+
#![no_std]
4+
5+
use cortex_m_rt::entry;
6+
use embedded_hal::delay::DelayNs;
7+
use rtt_target::{
8+
rtt_init_print,
9+
rprintln,
10+
};
11+
use panic_rtt_target as _;
12+
use microbit::board::Board;
13+
use microbit::hal::timer::Timer;
14+
15+
#[entry]
16+
fn main() -> ! {
17+
rtt_init_print!();
18+
19+
let board = Board::take().unwrap();
20+
21+
let mut timer = Timer::new(board.TIMER0);
22+
23+
loop {
24+
timer.delay_ms(1_000u32);
25+
rprintln!("1000 ms passed");
26+
}
27+
}
28+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![deny(unsafe_code)]
2+
#![no_main]
3+
#![no_std]
4+
5+
use cortex_m_rt::entry;
6+
use rtt_target::{
7+
rtt_init_print,
8+
rprintln,
9+
};
10+
use panic_rtt_target as _;
11+
use embedded_hal::{
12+
delay::DelayNs,
13+
digital::OutputPin,
14+
};
15+
use microbit::board::Board;
16+
use microbit::hal::timer::Timer;
17+
18+
#[entry]
19+
fn main() -> ! {
20+
rtt_init_print!();
21+
22+
let mut board = Board::take().unwrap();
23+
24+
let mut timer = Timer::new(board.TIMER0);
25+
26+
board.display_pins.col1.set_low().unwrap();
27+
let mut row1 = board.display_pins.row1;
28+
29+
loop {
30+
row1.set_low().unwrap();
31+
rprintln!("Dark!");
32+
timer.delay_ms(1_000_u32);
33+
34+
row1.set_high().unwrap();
35+
rprintln!("Light!");
36+
timer.delay_ms(1_000_u32);
37+
}
38+
}

microbit/src/05-led-roulette/it-blinks.md

Lines changed: 5 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,8 @@ Inside our MCU, several so-called "timers" exist. They can do various things reg
1616
including simply pausing the execution of our program for a fixed amount of time. A very
1717
simple delay-based program that prints something every second might for example look like this:
1818

19-
```rs
20-
#![deny(unsafe_code)]
21-
#![no_main]
22-
#![no_std]
23-
24-
use cortex_m_rt::entry;
25-
use embedded_hal::delay::DelayNS;
26-
use rtt_target::{
27-
rtt_init_print,
28-
rprintln,
29-
};
30-
use panic_rtt_target as _;
31-
use microbit::board::Board;
32-
use microbit::hal::timer::Timer;
33-
34-
#[entry]
35-
fn main() -> ! {
36-
rtt_init_print!();
37-
38-
let board = Board::take().unwrap();
39-
40-
let mut timer = Timer::new(board.TIMER0);
41-
42-
loop {
43-
timer.delay_ms(1_000u32);
44-
rprintln!("1000 ms passed");
45-
}
46-
}
19+
``` rust
20+
{{#include examples/it-blinks-1.rs}}
4721
```
4822

4923
Note that we changed our panic implementation from `panic_halt` to
@@ -52,7 +26,7 @@ RTT lines from `Cargo.toml` and comment the `panic-halt` one out,
5226
since Rust only allows one panic implementation at a time.
5327

5428
In order to actually see the prints we have to change `Embed.toml` like shown on the marked lines (`<--- Here`):
55-
```
29+
```toml
5630
[default.general]
5731
# chip = "nrf52833_xxAA" # uncomment this line for micro:bit V2
5832
# chip = "nrf51822_xxAA" # uncomment this line for micro:bit V1
@@ -76,45 +50,8 @@ Now we've arrived at the point where we can combine our new knowledge about GPIO
7650
in order to actually make an LED on the back of the micro:bit blink. The resulting program is really just
7751
a mash-up of the one above and the one that turned an LED on in the last section and looks like this:
7852

79-
```rs
80-
#![deny(unsafe_code)]
81-
#![no_main]
82-
#![no_std]
83-
84-
use cortex_m_rt::entry;
85-
use rtt_target::{
86-
rtt_init_print,
87-
rprintln,
88-
};
89-
use panic_rtt_target as _;
90-
use embedded_hal::{
91-
delay::DelayNS,
92-
digital::OutputPin,
93-
};
94-
use microbit::board::Board;
95-
use microbit::hal::timer::Timer;
96-
97-
#[entry]
98-
fn main() -> ! {
99-
rtt_init_print!();
100-
101-
let mut board = Board::take().unwrap();
102-
103-
let mut timer = Timer::new(board.TIMER0);
104-
105-
board.display_pins.col1.set_low().unwrap();
106-
let mut row1 = board.display_pins.row1;
107-
108-
loop {
109-
row1.set_low().unwrap();
110-
rprintln!("Dark!");
111-
timer.delay_ms(1_000_u16);
112-
113-
row1.set_high().unwrap();
114-
rprintln!("Light!");
115-
timer.delay_ms(1_000_u16);
116-
}
117-
}
53+
``` rust
54+
{{#include examples/it-blinks-2.rs}}
11855
```
11956

12057
And after putting the code into `src/main.rs` and a final `cargo embed` (with the proper flags)

0 commit comments

Comments
 (0)