#embassy #async #no-std #blinky

no-std blinker

easily creating async blinky programs for embedded systems

2 releases

new 0.1.1 Dec 16, 2024
0.1.0 Dec 16, 2024

#953 in Embedded development

Download history 124/week @ 2024-12-11

124 downloads per month

MIT license

10KB
108 lines

Blinker

A no_std led blinking library for embedded systems.

Features

  • Async/await support
  • Configurable blink patterns through Schedule
  • Support for both finite and infinite blinking sequences
  • No heap allocation (uses heapless Vec)
use blinker::{Blinker, Schedule};
use embassy_time::Duration;
use embedded_hal::digital::StatefulOutputPin;

async fn blink_task(led_pin: impl StatefulOutputPin) {
    let mut blinker = Blinker::<_, 1>::new(led_pin);
    // Blink with 500ms interval
    let _ = blinker.push_schedule(Schedule::Infinite(Duration::from_millis(500)));
    // Run the blink pattern
    loop {
        let _ = blinker.step().await;
    }
}

See docs for more details.


lib.rs:

no_std led blinking library for embedded systems.

provides a Blinker struct that can control an output pin to create blinking patterns, and supports both finite and infinite blinking Schedules with configurable durations.

Features

  • async/await support
  • Configurable blink patterns through Schedule
  • Support for both finite and infinite blinking sequences
  • No heap allocation (uses heapless::Vec)

The main purpose of this library is to provide a simple and efficient way to control an led to create blinking patterns, but it can also be used for any purpose that requires toggling an output pin according to specific patterns.

Example

async fn blink_task(led_pin: impl StatefulOutputPin) {
    let mut blinker = Blinker::<_, 1>::new(led_pin);
    // Blink with 500ms interval
    let _ = blinker.push_schedule(Schedule::Infinite(Duration::from_millis(500)));
    // Run the blink pattern
    loop {
        let _ = blinker.step().await;
    }
}
async fn blink_task(led_pin: impl StatefulOutputPin, rx: Receiver<Event>) {
    let mut blinker = Blinker::<_, 2>::new(led_pin);
    // Blink with 500ms interval
    let _ = blinker.push_schedule(Schedule::Ininite(Duration::from_millis(500)));
    // Run the blink pattern
    loop {
        if let Either::Second(Event::ButtonPushed) = select(blinker.step().await, rx.recv()).await {
            // ignore overflow
            let _ = blinker.push_schedule(Schedule::Ininite(Duration::from_millis(100)));
        }
    }
}

Dependencies

~1.5MB
~30K SLoC