Lights! - MisterRager/Codelab-Indicator-Lights GitHub Wiki
Lights!
source: Adafruit Neopixel Uberguide
This module may lack a screen, but the 22 "neopixel" lights arranged around the edge on the backside are bright (2.5W/each at full white) and individually addressable with 24 bits of color (8 per channel, rgb). Provided is ui/color_ring.h
, a collection of utility functions that manipulate the lights:
Pixel
: aunion
betweenuint32_t
and astruct
that accesses the first three bytes asuint8_t
#ws2812_control_init
: initialize the RMT peripheral for writing out to the neopixels#ws2812_write_leds
: copy the given buffer to the RMT DMA buffers for output (flush)#pixel_rgb
: a factory function for producingPixel
instances#rgb_spectrum
: a helper function for producing "rainbow" gradients#ring_dim
: linearly scale the brightness of all the neopixels#ring_fill
: given aPixel
, set all of the lights to the that color#ring_fill_rainbow
: using#rgb_spectrum
, paint a rainbow from red through to violet
The two rotation animation functions are a bit special and are worth specific attention, so don't worry about them, yet.
Before the rmt peripheral can be used, it has to be initialized with #ws2812_control_init
. Flush the color buffer with #ws2812_write_leds
.
#include "ui/color_ring.h"
struct led_state ring;
static void red_dots()
{
// black out everything
ring_fill(pixel_rgb(0, 0, 0), &ring);
for (int k = 0; k < NUM_LEDS; K+=2)
{
ring.leds[k].components.r = 20;
}
ws2812_write_leds(ring);
}
...
void app_main()
{
ws2812_control_init();
red_dots();
}