@@ -16,34 +16,8 @@ Inside our MCU, several so-called "timers" exist. They can do various things reg
16
16
including simply pausing the execution of our program for a fixed amount of time. A very
17
17
simple delay-based program that prints something every second might for example look like this:
18
18
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}}
47
21
```
48
22
49
23
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,
52
26
since Rust only allows one panic implementation at a time.
53
27
54
28
In order to actually see the prints we have to change ` Embed.toml ` like shown on the marked lines (` <--- Here ` ):
55
- ```
29
+ ``` toml
56
30
[default .general ]
57
31
# chip = "nrf52833_xxAA" # uncomment this line for micro:bit V2
58
32
# 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
76
50
in order to actually make an LED on the back of the micro: bit blink. The resulting program is really just
77
51
a mash-up of the one above and the one that turned an LED on in the last section and looks like this:
78
52
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}}
118
55
```
119
56
120
57
And after putting the code into ` src/main.rs ` and a final ` cargo embed ` (with the proper flags)
0 commit comments