blob: f37fd1274d8b7d8f67511e5c5956b1fb97a958d7 [file] [log] [blame]
#![no_std]
use libtock::led;
use libtock::result::TockResult;
use libtock::timer;
use libtock::timer::Duration;
#[libtock::main]
async fn main() -> TockResult<()> {
let num_leds = led::count()?;
let context = timer::DriverContext::create()?;
let mut driver = context.create_timer_driver()?;
let timer_driver = driver.activate()?;
// Blink the LEDs in a binary count pattern and scale
// to the number of LEDs on the board.
let mut count: usize = 0;
loop {
for i in 0..num_leds {
if count & (1 << i) == (1 << i) {
led::get(i).unwrap().on()?;
} else {
led::get(i).unwrap().off()?;
}
}
count = count.wrapping_add(1);
// This delay uses an underlying timer in the kernel.
timer_driver.sleep(Duration::from_ms(250)).await?;
}
}