-
Notifications
You must be signed in to change notification settings - Fork 7
RGB LED
The RGB LED API drives an addressable WS2812B LED strip from a selectable data pin. It supports direct per-LED colour control, a set of built-in non-blocking animations, and an ownership switch that hands the strip between your code and the firmware's built-in flight-status indicator.
Only one strip is active at a time, chosen at init. Up to RGB_MAX_LEDS
(64) LEDs are supported.
Selects which vetted {pin, timer, DMA} slot drives the strip. Pass one to RGB_Init().
typedef enum {
RGB_1 = 0, // PA8 TIM1_CH1 DMA1_Ch2 PPM RC-IN / 5th motor pin
RGB_2, // PB6 TIM4_CH1 DMA1_Ch1 shares DMA with ADC1
RGB_3, // PB14 TIM15_CH1 DMA1_Ch5 ! disables flash/blackbox
RGB_4, // PA13 TIM4_CH3 DMA1_Ch5 ! SWDIO debug pin
RGB_5, // PA14 TIM8_CH2 DMA2_Ch5 ! SWCLK debug pin
RGB_6, // PB4 TIM3_CH1 DMA1_Ch6 free pin (recommended)
RGB_7, // PB5 TIM17_CH1 DMA1_Ch1 free pin, shares ADC1 DMA
RGB_8, // PA15 TIM8_CH1 DMA2_Ch3 default flight-status pin
} peripheral_rgb_pin_e;Pin conflicts: slots marked
!collide with SWD debug (RGB_4/RGB_5) or flash/blackbox (RGB_3).RGB_6is the recommended free pin;RGB_8(PA15) is the default flight-status pin. Seedocs/WS2812_RGB.mdfor the full matrix.
Selects who owns the strip.
typedef enum {
RGB_USER = 0, // user code drives the strip via RGB_* calls
RGB_SYSTEM // firmware draws the flight-status indicator
} rgb_control_e;The built-in non-blocking animation to play. Pass one to RGB_StartAnimation().
RGB_ANIM_NONE, RGB_ANIM_CHASE, RGB_ANIM_METEOR, RGB_ANIM_DUAL_CHASE,
RGB_ANIM_BOUNCE, RGB_ANIM_COLOR_WIPE, RGB_ANIM_FILL_DRAIN, RGB_ANIM_DROP,
RGB_ANIM_HOURGLASS, RGB_ANIM_SWEEP_STACK, RGB_ANIM_SWEEP_UNSTACK,
RGB_ANIM_CONVERGE, RGB_ANIM_EXPAND, RGB_ANIM_BREATHE, RGB_ANIM_BLINK,
RGB_ANIM_ALTERNATE_BLINK, RGB_ANIM_SPARKLE, RGB_ANIM_FIRE, RGB_ANIM_RAINBOW,
RGB_ANIM_THEATER_CHASE, RGB_ANIM_WAVE, RGB_ANIM_DUAL_SCANControls which way patterns travel.
typedef enum {
RGB_DIR_FORWARD = 0, // LED 0 -> LED N
RGB_DIR_REVERSE // LED N -> LED 0
} RGB_Direction_e;Initialises the strip on the selected pin slot with led_count LEDs (1 to
RGB_MAX_LEDS). Call once in plutoInit(). The strip starts in RGB_SYSTEM
mode (firmware paints the flight-status indicator).
Switches ownership. RGB_USER lets your RGB_* calls drive the strip;
RGB_SYSTEM hands it back to the built-in flight-status indicator, which the
firmware updates automatically every control loop.
Releases the strip and frees its pin/timer/DMA slot.
Returns the number of LEDs configured at init.
All colour edits write to a back buffer and are not visible until RGB_Show().
Sets a single LED's colour.
Sets every LED to the same colour.
Sets a single LED from HSV (hue 0-359, saturation/value 0-255).
Fills a range of LEDs [start, end] with one colour.
Scales overall brightness (0-100%).
Clears the buffer (all LEDs off). Still requires RGB_Show() to take effect.
Pushes the buffer to the physical strip via DMA.
Animations are non-blocking: start one, then advance it every loop.
void RGB_StartAnimation(RGB_Animation_e animation, uint16_t speed_ms, RGB_Direction_e direction, uint8_t r, uint8_t g, uint8_t b)
Starts an animation at speed_ms per frame in the given direction and base
colour. Colour is ignored by palette-driven effects (e.g. RGB_ANIM_RAINBOW).
Advances the active animation if its frame is due. Call every plutoLoop()
iteration. Calls RGB_Show() internally - do not call RGB_Show() yourself
while an animation is running.
Stops the animation and turns all LEDs off immediately.
Returns true while an animation is active.
#include "PlutoPilot.h"
void plutoInit ( void ) {
RGB_Init ( RGB_6, 8 ); // 8-LED strip on PB4 (recommended free pin)
}
void onLoopStart ( void ) {
RGB_Control ( RGB_USER ); // take the strip in Developer Mode
RGB_StartAnimation ( RGB_ANIM_RAINBOW, 100, RGB_DIR_FORWARD, 0, 0, 0 );
}
void plutoLoop ( void ) {
RGB_UpdateAnimation(); // advance the animation each loop
}
void onLoopFinish ( void ) {
RGB_StopAnimation();
RGB_Control ( RGB_SYSTEM ); // hand the strip back to flight status
}Static colours instead of an animation:
RGB_Control ( RGB_USER );
RGB_SetColor ( 0, 255, 0, 0 ); // LED 0 red
RGB_SetColor ( 1, 0, 255, 0 ); // LED 1 green
RGB_SetBrightness ( 50 ); // 50% brightness
RGB_Show(); // push to the stripMagisV2 © 2026 Drona Aviation | Licensed under GPL-3.0 | Report Issues