EVNRGBLED#

These peripherals use WS2812B RGB LEDs, which feature 3 brightness-controlled channels for Red, Green and Blue.

Normally, a microcontroller would need to transmit a signal of carefully timed HIGHs and LOWs to control the LEDs, which would block the rest of the program due to the use of delay(). However, this library uses Programmable IO (PIO) to handle the transmissions, so the main program loop is not blocked when transmitting to the LEDs.

Another thing to note is that these can be daisy-chained, so you can control up to 48 LEDs (6 Peripherals) with one Servo port!

Note

Each instance of EVNRGBLED (4 max) consumes 1 of the RP2040’s 8 PIO state machines, so keep this in mind if you are using PIO for your own purposes.

Note

EVNRGBLED consumes some of the RP2040’s DMA peripherals. See this page for more info.

Wiring (Servo)#

Host

Peripheral

Description

SIG

IN

Signal

5V

VCC

5V Power

GND

GND

Ground (0V)

Chaining Multiple RGB LEDs#

It’s possible to chain up to 6 RGB LED Peripherals in a row without needing to use more Servo ports.

Simply connect the OUT of one Peripheral to the IN pin of the next one in the chain.

Peripheral

Next Peripheral

Description

OUT

IN

Signal

VCC

VCC

5V Power

GND

GND

Ground (0V)

Warning

Each RGB LED consumes 60mA of current at max brightness. Using 6 sticks (48 RGB LEDs) consumes 2.88A maximum, which is close to the 3A limit of the Servo ports. Keep this in mind if you have other peripherals powered by Servo ports!

Constructor#

class EVNRGBLED(uint8_t port, uint8_t led_count = 8, bool invert = false)#
Parameters
  • port – Servo port (1-4)

  • led_count – Number of LEDs connected to the servo port. Defaults to 8

  • invert – Whether order of LED indexes should be inverted

Functions#

bool begin()

Initializes RGB LED Array. Call this function before using the other functions.

Returns

Boolean indicating whether the RGB LED array was successfully initialized.

void end()

Deinitializes RGB LED Array and releases PIO state machine and DMA channel consumed by it. Does not clear the data currently written to the RGB LED Array.

Set Functions#

void setLEDCount(uint8_t led_count)
Parameters

led_count – Number of LEDs in array

void setInvert(bool enable)

By default, the LED with index 0 is the one closest to the IN wire. When enabled (set to true), the index order is inverted, so that index 0 is the LED furthest from the IN wire.

Dir

Whether LED index is inverted

Get Functions#

uint8_t getLEDCount()
Returns

number of LEDs in the array

bool getInvert()
Returns

Whether LED index is inverted

Display Functions#

void writeOne(uint8_t led, uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, bool show = true)

Updates given LED’s RGB values in buffer and if show is true, writes buffer to peripheral.

Parameters
  • led – Index of LED to update (0 to (led_count-1)). LED 0 is the LED closest to the signal & power pins

  • r – Red channel intensity (0-255). Defaults to 0

  • g – Green channel intensity (0-255). Defaults to 0

  • b – Blue channel intensity (0-255). Defaults to 0

  • show – Whether to write buffer to LEDs. Defaults to true

void clearOne(uint8_t led, bool show = true)

Set given LED to turn off in buffer and if show is true, writes buffer to peripheral.

Parameters
  • led – Index of LED to update (0 to (led_count-1)). LED 0 is the LED closest to the signal & power pins

  • show – Whether to write buffer to LEDs. Defaults to true

void writeLine(uint8_t start_led, uint8_t end_led, uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, bool show = true)

Update given range of LEDs’ RGB values in buffer and if show is true, writes buffer to peripheral.

Parameters
  • start_led – Starting index of LED to update (0 to (led_count-1)). LED 0 is the LED closest to the signal & power pins

  • end_led – Ending index of LED to update (0 to (led_count-1)). This LED will be updated as well.

  • r – Red channel intensity (0-255). Defaults to 0

  • g – Green channel intensity (0-255). Defaults to 0

  • b – Blue channel intensity (0-255). Defaults to 0

  • show – Whether to write buffer to LEDs. Defaults to true

void writeLine(uint8_t start_led, uint8_t end_led, uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, bool show = true)

Update given range of LEDs to turn off in buffer and if show is true, writes buffer to peripheral.

Parameters
  • start_led – Starting index of LED to update (0 to (led_count-1)). LED 0 is the LED closest to the signal & power pins

  • end_led – Ending index of LED to update (0 to (led_count-1)). This LED will be updated as well.

  • show – Whether to write buffer to LEDs. Defaults to true

void writeAll(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, bool show = true)

Updates all LEDs’ RGB values in buffer and if show is true, writes buffer to peripheral.

Parameters
  • r – Red channel intensity (0-255). Defaults to 0

  • g – Green channel intensity (0-255). Defaults to 0

  • b – Blue channel intensity (0-255). Defaults to 0

  • show – Whether to write buffer to LEDs. Defaults to true

void clearAll(bool show = true)

Set all LEDs to turn off in buffer and if show is true, writes buffer to peripheral, essentially turning all LEDs off.

Parameters

show – Whether to write buffer to LEDs. Defaults to true

void update()

Writes buffer to LEDs.

By default, this function is internally called at the end of all the write###() / clear###() functions.

However, it may be more useful for you to make multiple changes to the buffer using the above functions with show set to false, before calling show() at the end to update the LEDs.

This approach can achieve nicer visual output (all pixels change simultaneously) or faster updates (as update() is only called once).