Skip to content

Commit 5607a83

Browse files
committed
Factor out 05-led-roulette examples
1 parent 0216f34 commit 5607a83

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#![deny(unsafe_code)]
2+
#![no_main]
3+
#![no_std]
4+
5+
use aux5::{Delay, DelayMs, LedArray, OutputSwitch, entry};
6+
7+
#[entry]
8+
fn main() -> ! {
9+
let (mut delay, mut leds): (Delay, LedArray) = aux5::init();
10+
11+
let ms = 50_u8;
12+
loop {
13+
for curr in 0..8 {
14+
let next = (curr + 1) % 8;
15+
16+
leds[next].on().ok();
17+
delay.delay_ms(ms);
18+
leds[curr].off().ok();
19+
delay.delay_ms(ms);
20+
}
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![deny(unsafe_code)]
2+
#![no_main]
3+
#![no_std]
4+
5+
use aux5::{entry, Delay, DelayMs, LedArray, OutputSwitch};
6+
7+
#[entry]
8+
fn main() -> ! {
9+
let (mut delay, mut leds): (Delay, LedArray) = aux5::init();
10+
11+
let half_period = 500_u16;
12+
13+
loop {
14+
leds[0].on().ok();
15+
delay.delay_ms(half_period);
16+
17+
leds[0].off().ok();
18+
delay.delay_ms(half_period);
19+
}
20+
}

src/05-led-roulette/my-solution.md

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,7 @@ What solution did you come up with?
55
Here's mine:
66

77
``` rust
8-
#![deny(unsafe_code)]
9-
#![no_main]
10-
#![no_std]
11-
12-
use aux5::{Delay, DelayMs, LedArray, OutputSwitch, entry};
13-
14-
#[entry]
15-
fn main() -> ! {
16-
let (mut delay, mut leds): (Delay, LedArray) = aux5::init();
17-
18-
let ms = 50_u8;
19-
loop {
20-
for curr in 0..8 {
21-
let next = (curr + 1) % 8;
22-
23-
leds[next].on().ok();
24-
delay.delay_ms(ms);
25-
leds[curr].off().ok();
26-
delay.delay_ms(ms);
27-
}
28-
}
29-
}
30-
8+
{{#include examples/my-solution.rs}}
319
```
3210

3311
One more thing! Check that your solution also works when compiled in "release" mode:

src/05-led-roulette/the-led-and-delay-abstractions.md

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,7 @@ and exposes two methods: `on` and `off` which can be used to turn the LED on or
1414
Let's try out these two abstractions by modifying the starter code to look like this:
1515

1616
``` rust
17-
#![deny(unsafe_code)]
18-
#![no_main]
19-
#![no_std]
20-
21-
use aux5::{entry, Delay, DelayMs, LedArray, OutputSwitch};
22-
23-
#[entry]
24-
fn main() -> ! {
25-
let (mut delay, mut leds): (Delay, LedArray) = aux5::init();
26-
27-
let half_period = 500_u16;
28-
29-
loop {
30-
leds[0].on().ok();
31-
delay.delay_ms(half_period);
32-
33-
leds[0].off().ok();
34-
delay.delay_ms(half_period);
35-
}
36-
}
37-
17+
{{#include examples/the-led-and-delay-abstractions.rs}}
3818
```
3919

4020
Now build it:

0 commit comments

Comments
 (0)