Skip to main content

ferriswheel/
lib.rs

1#![cfg_attr(not(test), no_std)]
2//! RGB LED ring effects and animations.
3//!
4//! This crate provides reusable animation effects for circular LED rings.
5//! It is `no_std` compatible for embedded use.
6//!
7//! All effects implement the [`Effect`] trait, which provides a uniform
8//! interface for rendering animations into an `RGB8` buffer.
9//!
10//! # Available Effects
11//!
12//! - [`RainbowEffect`] — smooth rainbow gradient rotation
13//! - [`PulseEffect`] — heartbeat animation: sine-wave brightness with a pause at the floor
14//! - [`BreatheEffect`] — breathing animation: symmetric full-sine brightness with no pause
15//! - [`SpinnerEffect`] — rotating dot with fading tail (linear decay, brightness floor)
16//! - [`MeteorEffect`] — meteor / comet: bright head with exponentially-decaying tail
17//! - [`TwinkleEffect`] — ambient sparkle: random LEDs flash to peak brightness then decay
18//! - [`FireEffect`] — fire simulation: heat diffuses upward from a sparking base
19//! - [`CylonEffect`] — Cylon / bouncing scanner: bright head sweeps back and forth with fading tail
20//! - [`KnightRiderEffect`] — Knight Rider / dual-headed scanner: two heads sweep in opposite directions
21//! - [`ChaseEffect`] — moving a solid segment around the ring
22//! - [`FlashEffect`] — rapid on/off toggle with configurable duty cycle
23//! - [`ProgressEffect`] — proportional ring fill
24//! - [`SectionEffect`] — weighted color sections on a ring
25//! - [`RainbowCometEffect`] — Rainbow comet: orbiting head with a hue-cycling fading tail
26//!
27//! # Utilities
28//!
29//! - [`ColorPalette`] — three-color theme for effects
30//! - [`fill_solid`] — fill a buffer with a single color
31//! - [`sine_wave`] — half-wave rectified sine lookup (0→255→0 then plateau at 0)
32//! - [`sine_full`] — full symmetric sine lookup (0→255→0, no plateau)
33//! - [`scale_brightness`] — scale an RGB color's brightness
34//! - [`lerp_color`] — linearly interpolate between two colors
35//!
36//! # Color type
37//!
38//! All effects operate on [`RGB8`], re-exported here from the [`rgb`] crate.
39//! Downstream crates do not need a direct `rgb` dependency — `use ferriswheel::RGB8`
40//! is sufficient.
41//!
42//! # Example
43//!
44//! ```
45//! use ferriswheel::{Effect, RainbowEffect, Direction, RGB8};
46//!
47//! let mut rainbow = RainbowEffect::new(12).unwrap();
48//! let mut buffer = [RGB8::default(); 12];
49//!
50//! // Fill the buffer with rainbow colors and advance animation
51//! rainbow.update(&mut buffer).unwrap();
52//!
53//! // Use as a trait object
54//! let effect: &dyn Effect = &rainbow;
55//! effect.current(&mut buffer).unwrap();
56//! ```
57
58mod breathe;
59mod chase;
60mod cylon;
61mod effect;
62mod fire;
63mod flash;
64mod hsv;
65mod knight_rider;
66mod meteor;
67mod palette;
68mod progress;
69mod pulse;
70mod rainbow;
71mod rainbow_comet;
72mod section;
73mod spinner;
74mod twinkle;
75mod util;
76
77pub use rgb::RGB8;
78
79pub use breathe::BreatheEffect;
80pub use chase::ChaseEffect;
81pub use cylon::CylonEffect;
82pub use effect::{Direction, Effect, EffectError, MAX_LEDS};
83pub use fire::FireEffect;
84pub use flash::FlashEffect;
85pub use hsv::hsv_to_rgb;
86pub use knight_rider::KnightRiderEffect;
87pub use meteor::MeteorEffect;
88pub use palette::ColorPalette;
89pub use progress::ProgressEffect;
90pub use pulse::PulseEffect;
91pub use rainbow::RainbowEffect;
92pub use rainbow_comet::RainbowCometEffect;
93pub use section::{SectionEffect, MAX_SECTIONS};
94pub use spinner::SpinnerEffect;
95pub use twinkle::TwinkleEffect;
96pub use util::{fill_solid, lerp_color, scale_brightness, sine_full, sine_wave};
97
98// When `smart-leds-compat` is enabled, this forces `smart-leds-trait` into the
99// dependency graph and makes compilation fail if its `rgb::RGB8` differs from
100// ours — i.e. if the two crates resolve to incompatible `rgb` versions.
101#[cfg(feature = "smart-leds-compat")]
102fn _assert_rgb8_same(c: rgb::RGB8) -> smart_leds_trait::RGB8 {
103    c
104}