File tree Expand file tree Collapse file tree 2 files changed +46
-44
lines changed
microbit/src/05-led-roulette Expand file tree Collapse file tree 2 files changed +46
-44
lines changed Original file line number Diff line number Diff line change
1
+ #![ deny( unsafe_code) ]
2
+ #![ no_main]
3
+ #![ no_std]
4
+
5
+ use cortex_m_rt:: entry;
6
+ use rtt_target:: rtt_init_print;
7
+ use panic_rtt_target as _;
8
+ use embedded_hal:: delay:: DelayNs ;
9
+ use microbit:: {
10
+ board:: Board ,
11
+ display:: blocking:: Display ,
12
+ hal:: Timer ,
13
+ } ;
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
+ let mut display = Display :: new ( board. display_pins ) ;
23
+
24
+ // Setup the display delay so the math works as expected later.
25
+ display. set_delay_ms ( 1 ) ;
26
+
27
+ let light_it_all = [
28
+ [ 1 , 1 , 1 , 1 , 1 ] ,
29
+ [ 1 , 1 , 1 , 1 , 1 ] ,
30
+ [ 1 , 1 , 1 , 1 , 1 ] ,
31
+ [ 1 , 1 , 1 , 1 , 1 ] ,
32
+ [ 1 , 1 , 1 , 1 , 1 ] ,
33
+ ] ;
34
+
35
+ loop {
36
+ // Show light_it_all for 1000ms
37
+ display. show ( & mut timer, light_it_all, 1_000 ) ;
38
+
39
+ // clear the display again
40
+ display. clear ( ) ;
41
+
42
+ timer. delay_ms ( 1000_u32 ) ;
43
+ }
44
+ }
45
+
Original file line number Diff line number Diff line change @@ -18,50 +18,7 @@ Since working with the LED pins separately is quite annoying
18
18
you can use the display API provided by the BSP. It works like this:
19
19
20
20
``` rust
21
- #![deny(unsafe_code)]
22
- #![no_main]
23
- #![no_std]
24
-
25
- use cortex_m_rt :: entry;
26
- use rtt_target :: rtt_init_print;
27
- use panic_rtt_target as _;
28
- use embedded- hal :: delay :: DelayNS ;
29
- use microbit :: {
30
- board :: Board ,
31
- display :: blocking :: Display ,
32
- hal :: Timer ,
33
- };
34
-
35
- #[entry]
36
- fn main () -> ! {
37
- rtt_init_print! ();
38
-
39
- let board = Board :: take (). unwrap ();
40
-
41
- let mut timer = Timer :: new (board . TIMER0 );
42
- let mut display = Display :: new (board . display_pins);
43
-
44
- // Setup the display delay so the math works as expected later.
45
- display . set_delay_ms (1 );
46
-
47
- let light_it_all = [
48
- [1 , 1 , 1 , 1 , 1 ],
49
- [1 , 1 , 1 , 1 , 1 ],
50
- [1 , 1 , 1 , 1 , 1 ],
51
- [1 , 1 , 1 , 1 , 1 ],
52
- [1 , 1 , 1 , 1 , 1 ],
53
- ];
54
-
55
- loop {
56
- // Show light_it_all for 1000ms
57
- display . show (& mut timer , light_it_all , 1_000 );
58
-
59
- // clear the display again
60
- display . clear ();
61
-
62
- timer . delay_ms (1000_u32 );
63
- }
64
- }
21
+ {{#include examples / the - challenge . rs}}
65
22
```
66
23
67
24
Equipped with this API your task basically boils down to just having
You can’t perform that action at this time.
0 commit comments