pub struct Led<'a>(/* private fields */);target_os=none only.Expand description
A device abstraction for a single digital LED with animation support.
§Hardware Requirements
This device requires a single GPIO pin connected to an LED. The LED can be wired for either active-high (default) or active-low operation. The device supports both polarities and controls the pin internally.
Active-high wiring (default): LED anode (long leg) → 220Ω resistor → GPIO pin, LED cathode (short leg) → GND Active-low wiring: LED anode (long leg) → 3.3V, LED cathode (short leg) → 220Ω resistor → GPIO pin
§Example
use device_envoy::{Result, led::{Led, LedStatic, OnLevel}};
use embassy_time::Duration;
use embassy_rp::gpio::Level;
async fn example(p: embassy_rp::Peripherals, spawner: embassy_executor::Spawner) -> Result<()> {
static LED_STATIC: LedStatic = Led::new_static();
let led = Led::new(&LED_STATIC, p.PIN_1, OnLevel::High, spawner)?;
// Turn the LED on
led.set_level(Level::High);
embassy_time::Timer::after(Duration::from_secs(1)).await;
// Turn the LED off
led.set_level(Level::Low);
embassy_time::Timer::after(Duration::from_millis(500)).await;
// Play a blinking animation (looping: 200ms on, 200ms off)
led.animate(&[(Level::High, Duration::from_millis(200)), (Level::Low, Duration::from_millis(200))]);
core::future::pending().await // run forever
}The device runs a background task that handles state transitions and animations.
Create the device once with Led::new and use the returned handle for all updates.
Implementations§
Source§impl Led<'_>
impl Led<'_>
Sourcepub fn new<P: Pin>(
led_static: &'static LedStatic,
pin: Peri<'static, P>,
on_level: OnLevel,
spawner: Spawner,
) -> Result<Self>
pub fn new<P: Pin>( led_static: &'static LedStatic, pin: Peri<'static, P>, on_level: OnLevel, spawner: Spawner, ) -> Result<Self>
Creates a single LED device and spawns its background task; see Led docs.
Sourcepub const fn new_static() -> LedStatic
pub const fn new_static() -> LedStatic
Sourcepub fn set_level(&self, level: Level)
pub fn set_level(&self, level: Level)
Set the LED level immediately, replacing any running animation.
See Led struct example for usage.
Sourcepub fn animate<I>(&self, frames: I)
pub fn animate<I>(&self, frames: I)
Play a looped animation sequence of LED levels with durations.
Accepts any iterator yielding (Level, Duration) pairs or references, up to 32 frames. The animation will loop continuously until replaced by another command. See Led struct example for usage.
Auto Trait Implementations§
impl<'a> Freeze for Led<'a>
impl<'a> !RefUnwindSafe for Led<'a>
impl<'a> Send for Led<'a>
impl<'a> Sync for Led<'a>
impl<'a> Unpin for Led<'a>
impl<'a> !UnwindSafe for Led<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more