Skip to content

LEDs & Color

After this page you can set each light and change its color with the slider.

Your app controls 4 SK6812 RGBW LEDs (NeoPixel-compatible), each with red, green, blue and white channels. The device also has a separate red-only LED under the front grill and a red charge indicator on the back. Studio apps cannot control the separate red LED, and the studio emulator does not show it. The emulator's colored glow under the grill shows the front-bottom RGBW LED (pixel_Front_Bottom).


What is this?

RGBW means each LED has four channels:

  • R -- Red (0-255)
  • G -- Green (0-255)
  • B -- Blue (0-255)
  • W -- White (0-255)

The white channel is separate from red, green and blue. You can combine those three channels to make colors, or use the dedicated W channel for white light.

Why RGBW?

The W channel gives brighter white light and uses less power than maxing R, G and B. Mix it with red, green or blue to tint the result.


The 4 LED positions

Index Constant Location
0 pixel_Back Back of device
1 pixel_Front_Top Front, top
2 pixel_Front_Middle Front, middle
3 pixel_Front_Bottom Front, bottom

Use these constants when setting individual LEDs. The strip order is GRBW (see firmware details).


Setting colors

Add each example into update() of the studio starter, where its comment says. The starter calls setColorsOff() in begin() and end(), so every app starts and finishes with its lights off.

You can set all lights, the front three, or one pixel:

// Insert inside update(), just above display.display();
// Arguments after the pixel index are red, green, blue, white (0-255).
setDeterminedColorsAll(255, 0, 0, 0);          // All four red.
setDeterminedColorsFront(0, 255, 0, 0);        // Front three green.
HAL::setRgbLed(pixel_Front_Top, 255, 128, 0, 0); // Top orange.
HAL::setRgbLed(pixel_Front_Middle, 0, 0, 255, 50); // Middle blue + white.
// Use setColorsOff() to turn all four off.
Full code for this step

This full code is for code name MyApp (create it with App Name "My App"); if your app has another code name, change MyApp and myApp to yours.

In the starter, nullptr means a pointer has no object. * in a declaration marks a pointer (an address), and before a pointer reads its object. & in a type refers to an existing object; before a value it gives its address. const means the code cannot change the value through that declaration.

MyApp.cpp
#include "MyApp.h"
#include "globals.h"
#include "HAL.h"
#include "MenuManager.h"

MyApp myApp(HAL::buttonManager());
MyApp* MyApp::instance = nullptr;

MyApp::MyApp(ButtonManager& btnMgr) :
    buttonManager(btnMgr), display(HAL::displayProxy()), audio(HAL::audioManager()) { instance = this; }

// begin() runs once when your app opens from the menu.
// Set things up here: hook up the buttons and start with the lights off.
void MyApp::begin() {
    registerButtonCallbacks();
    setColorsOff();
}

// update() runs about 50 times a second while your app is open.
// Clear the screen, draw what you want, then show it.
// The case hides about 8 pixels at each screen corner, so keep text and
// important pixels out of those corners.
void MyApp::update() {
    display.clear();
    display.setTextAlignment(TEXT_ALIGN_CENTER);
    display.setFont(ArialMT_Plain_16);
    display.drawString(64, 24, "MyApp");
    // Arguments after the pixel index are red, green, blue, white (0-255).
    setDeterminedColorsAll(255, 0, 0, 0);          // All four red.
    setDeterminedColorsFront(0, 255, 0, 0);        // Front three green.
    HAL::setRgbLed(pixel_Front_Top, 255, 128, 0, 0); // Top orange.
    HAL::setRgbLed(pixel_Front_Middle, 0, 0, 255, 50); // Middle blue + white.
    // Use setColorsOff() to turn all four off.
    display.display();
}

// end() runs when your app closes. Let go of the buttons and turn the
// lights off (if your app plays sounds, call audio.stopTone() here too).
void MyApp::end() {
    unregisterButtonCallbacks();
    setColorsOff();
}

// The bottom-left button closes your app and goes back to the menu.
void MyApp::onButtonBackPressed(const ButtonEvent& event) {
    if (event.eventType == ButtonEvent_Released) {
        instance->end();
        MenuManager::instance().returnToMenu();
    }
}

void MyApp::registerButtonCallbacks() {
    buttonManager.registerCallback(button_BottomLeftIndex, onButtonBackPressed);
}

void MyApp::unregisterButtonCallbacks() {
    buttonManager.unregisterCallback(button_BottomLeftIndex);
}

LED changes appear automatically. Studio apps do not need updateStrip(); that call does nothing in app code.


Code example: color cycling and reactive LEDs

// Insert inside update(), just above display.display();
// mapToRainbow takes a hue from 0 to 4095 and a brightness from 0 to 255.
int input = (millis() / 20) % 4096;
uint8_t r, g, b;
mapToRainbow(input, 128, r, g, b);
setDeterminedColorsAll(r, g, b, 0);

int brightness = sliderPosition_8Bits_Inverted_Filtered;
HAL::setRgbLed(pixel_Front_Top, brightness, 0, brightness, 0);
Full code for this step

This full code is for code name MyApp (create it with App Name "My App"); if your app has another code name, change MyApp and myApp to yours.

MyApp.cpp
#include "MyApp.h"
#include "globals.h"
#include "HAL.h"
#include "MenuManager.h"

MyApp myApp(HAL::buttonManager());
MyApp* MyApp::instance = nullptr;

MyApp::MyApp(ButtonManager& btnMgr) :
    buttonManager(btnMgr), display(HAL::displayProxy()), audio(HAL::audioManager()) { instance = this; }

// begin() runs once when your app opens from the menu.
// Set things up here: hook up the buttons and start with the lights off.
void MyApp::begin() {
    registerButtonCallbacks();
    setColorsOff();
}

// update() runs about 50 times a second while your app is open.
// Clear the screen, draw what you want, then show it.
// The case hides about 8 pixels at each screen corner, so keep text and
// important pixels out of those corners.
void MyApp::update() {
    display.clear();
    display.setTextAlignment(TEXT_ALIGN_CENTER);
    display.setFont(ArialMT_Plain_16);
    display.drawString(64, 24, "MyApp");
    // mapToRainbow takes a hue from 0 to 4095 and a brightness from 0 to 255.
    int input = (millis() / 20) % 4096;
    uint8_t r, g, b;
    mapToRainbow(input, 128, r, g, b);
    setDeterminedColorsAll(r, g, b, 0);

    int brightness = sliderPosition_8Bits_Inverted_Filtered;
    HAL::setRgbLed(pixel_Front_Top, brightness, 0, brightness, 0);
    display.display();
}

// end() runs when your app closes. Let go of the buttons and turn the
// lights off (if your app plays sounds, call audio.stopTone() here too).
void MyApp::end() {
    unregisterButtonCallbacks();
    setColorsOff();
}

// The bottom-left button closes your app and goes back to the menu.
void MyApp::onButtonBackPressed(const ButtonEvent& event) {
    if (event.eventType == ButtonEvent_Released) {
        instance->end();
        MenuManager::instance().returnToMenu();
    }
}

void MyApp::registerButtonCallbacks() {
    buttonManager.registerCallback(button_BottomLeftIndex, onButtonBackPressed);
}

void MyApp::unregisterButtonCallbacks() {
    buttonManager.unregisterCallback(button_BottomLeftIndex);
}

The inverted slider value is low at the bottom and high at the top of the device. Moving it up makes the top light brighter. See The Slider for both directions.

Automatic light updates

Set the colors in update(). The firmware handles sending them to the LEDs. No extra call is needed.


Functions on this page

Call What it does
void HAL::setRgbLed(int index, uint8_t r, uint8_t g, uint8_t b, uint8_t w)
Example: HAL::setRgbLed(pixel_Front_Middle, 0, 0, 255, 0);
Set one RGBW LED; red, green, blue, white channels each use 0-255.
void HAL::setRgbLedsOff()
Example: HAL::setRgbLedsOff();
Turn all four RGBW LEDs off.
void setLed(int index, uint8_t r, uint8_t g, uint8_t b, uint8_t w)
Example: setLed(pixel_Front_Middle, 0, 0, 255, 0);
Short form of HAL::setRgbLed(): set one RGBW LED; red, green, blue, white channels each use 0-255.
void setColorsOff()
Example: setColorsOff();
Turn all four LEDs off; call in begin() and end().
void setDeterminedColorsFront(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
Example: setDeterminedColorsFront(0, 0, 255, 0);
Set the three front LEDs; RGBW channels each use 0-255.
void setDeterminedColorsAll(uint8_t r, uint8_t g, uint8_t b, uint8_t w)
Example: setDeterminedColorsAll(0, 0, 255, 0);
Set all four LEDs; RGBW channels each use 0-255.
void setRandomColors()
Example: setRandomColors();
Give the three front LEDs random red/green/blue channels from 0-9, with white off; back LED is unchanged.
void mapToRainbow(int input, uint8_t dim, uint8_t &red, uint8_t &green, uint8_t &blue)
Example: mapToRainbow(1024, 64, r, g, b);
Convert hue 0-4095 to red, green, blue output variables; dim scales brightness from 0-255.
const uint16_t pixel_Back = 0
Example: pixel_Back
Back RGBW LED.
const uint16_t pixel_Front_Bottom = 3
Example: pixel_Front_Bottom
Front Bottom RGBW LED.
const uint16_t pixel_Front_Middle = 2
Example: pixel_Front_Middle
Front Middle RGBW LED.
const uint16_t pixel_Front_Top = 1
Example: pixel_Front_Top
Front Top RGBW LED.

Framework details

Advanced: how the firmware drives the LEDs

You do not need these details to build apps in the studio. They describe the firmware internals for readers writing an app by hand and building it into the firmware.

RGBController and SK6812

The LEDs are SK6812-compatible (often called "NeoPixel"). The strip uses GRBW color order: the library sends Green, Red, Blue, White in that order. HAL::setRgbLed(index, r, g, b, w) and the color helpers accept red, green, blue, white in that order. They handle the wiring order for you. Studio apps do not have access to HAL::strip() or Adafruit_NeoPixel.

updateStrip throttling

Inside the firmware, updateStrip() sends buffered colors to the lights. Color changes mark the buffer as dirty, meaning it needs sending. The firmware:

  1. Checks whether any color has changed
  2. Only calls strip.show() when dirty and at least 33 ms have passed since the last show (about 30 updates per second)
  3. Clears the dirty flag after showing

This reduces blocking and avoids flicker while keeping updates smooth.

Firmware-only helpers

The LED functions your app can call are listed under Functions on this page. These are used inside the firmware:

Function Description
initRGB() Firmware only: initialize strip at boot
updateStrip() Does nothing in studio apps; firmware sends colors automatically
rainbow(int wait) Firmware only; studio apps can time colors with millis()