-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2_lets_get_blinky.rs
More file actions
39 lines (31 loc) · 1019 Bytes
/
day2_lets_get_blinky.rs
File metadata and controls
39 lines (31 loc) · 1019 Bytes
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
//! Light up three LEDs in sequence.
#![no_std]
#![no_main]
use defmt::info;
use embassy_executor::Spawner;
use embassy_rp::gpio::{Level, Output};
use embassy_time::Timer;
use {defmt_rtt as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let red = Output::new(p.PIN_18, Level::Low);
let amber = Output::new(p.PIN_19, Level::Low);
let green = Output::new(p.PIN_20, Level::Low);
let mut outputs = [("red", red), ("amber", amber), ("green", green)];
let mut i = 0;
loop {
// Based on the current iteration, which output should be "on"
let on = i % outputs.len();
for (index, (color, output)) in outputs.iter_mut().enumerate() {
if index == on {
info!("Flash {}", color);
output.set_high();
} else {
output.set_low();
}
}
Timer::after_millis(500).await;
i = on + 1;
}
}