RGB Macropad Individual LED control via QMK

Does anyone have a working example of keymap.c for the macropad that sets individual led rgb values using rgb_matrix_set_color?

I’ve been beating my head on the wall for days now. I can compile the firmware and install it, and I don’t get errors, and all of the key maps work correctly, but I also don’t get any change at all of the key LEDS. If I trigger the action (numlock status change), I occasionally see a “flash” of color for a microsecond, but that’s it.

  • VIA is disabled.
  • erase_flash.uf2 was uploaded to clear before uploading the modded firmware.
  • rules.mk has RGB_MATRIX_ENABLE = yes
  • I’m working from the framework fork of qmk, v0.3.1

It just seems like I’m missing a setting somewhere?

This is my Weird and wonderful keymap.c, from that same fork you using :slight_smile:

#include QMK_KEYBOARD_H
#define MAX_BRIGHTNESS 255
#define MIN_BRIGHTNESS 10

enum custom_keycodes {
    MACRO_BRIGHT_UP = SAFE_RANGE,
    MACRO_BRIGHT_DOWN
};

static uint8_t ledbright = 20; // Start at 20% brightness

bool increasing = true; // Tracks the direction of the color shift
uint8_t green = 255;
uint8_t blue = 0;

/*  Macropad key location to LED Index
     *         ┌────┬────┬────┬────┐
     *  row 1  │  5 │  2 │ 22 │ 17 │
     *         ├────┼────┼────┼────┤
     *  row 2  │  4 │  0 │ 20 │ 18 │
     *         ├────┼────┼────┼────┤
     *  row 3  │  7 │  1 │ 21 │ 16 │
     *         ├────┼────┼────┼────┤
     *  row 4  │  6 │  3 │ 23 │*19*│
     *         ├────┼────┼────┼────┤
     *  row 5  │  9 │*11*│ 15 │ 13 │
     *         ├────┼────┼────┼────┤
     *  row 6  │  8 │ 10 │ 14 │ 12 │
     *         └────┴────┴────┴────┘
     *        24 keys and LEDs total
     */

     // Hold down 2 and 6 to flash firmware to macro pad
     // which is index 11 and 19


uint8_t led_colors[24][3] = {
     [5] = { 64,  64,  64},  // Shurly this must be grey now.
     [2] = { 64,  64,  64},  // Shurly this must be grey now.
    [22] = { 64,  64,  64},  // light blue
    [17] = { 64,  64,  64},  // DeepDarkBlue
     [7] = {255,   0,   0},  // Red
     [1] = {255, 165,   0},  // Orange (leaning towards yellow)
    [21] = {255,   0,   0},  // Red
    [19] = {128, 128,  32},  // Red
     [6] = {255,  69,   0},  // Orange
     [3]  ={234, 255,   0},  // Yellowish with a hint of green
    [23] = {255,  69,   0},  // Orange
    [12] = {  0, 140, 139},  // Teal
     [8] = {  0, 220, 139},  // Teal
     [9] = {140,   0, 139},  // Purpleish
     [4] = {255, 255, 255},  // White
     [0] = {191, 191, 191},  // Dimmer white
    [20] = {128, 128, 128},  // can we call it grey yet ?
    [18] = { 64,  64,  64}   // Shurly this must be grey now.

};

// Default color for all other keys (Dark Blue)
#define DEFAULT_R 0
#define DEFAULT_G 0
#define DEFAULT_B 139

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    [0] = LAYOUT(
        KC_NO,    KC_NO,    KC_NO,    KC_NO,
        KC_1,     KC_2,     KC_3,     KC_4,
        KC_Q,     KC_W,     KC_E,     KC_TAB,
        KC_A,     KC_S,     KC_D,     KC_F,
        KC_LSFT,  KC_NO,    KC_NO,    TO(1),
        KC_LCTL,  KC_NO,    KC_NO,    KC_SPACE
    ),
    [1] = LAYOUT(
        KC_NO,    KC_NO,    KC_NO,    KC_NO,
        KC_NO,    KC_NO,    KC_NO,    KC_NO,
         KC_7,     KC_8,     KC_9,    KC_NO,
         KC_4,     KC_5,     KC_6,    KC_NO,
         KC_1,     KC_2,     KC_3,    TO(2),
        KC_NO,     KC_0,     KC_NO,    KC_NO
    ),
    [2] = LAYOUT(
        KC_NO,    KC_NO,    KC_NO,    KC_NO,
        KC_F1,    KC_F2,    KC_F3,    KC_F4,
        KC_Q,     KC_W,     KC_E,     KC_TAB,
        KC_A,     KC_S,     KC_D,     KC_F,
        KC_LSFT,  KC_NO,    KC_NO,    TO(3),
        KC_LCTL,  KC_NO,    KC_NO,    KC_SPACE
    ),
    [3] = LAYOUT(
        KC_NO,    KC_NO,    KC_NO,    KC_NO,
        KC_F1,    KC_F2,    KC_F3,    KC_F4,
        KC_HOME,  KC_UP,    KC_PGUP,  KC_TAB,
        KC_LEFT,  KC_DOWN,  KC_RIGHT, KC_F,
        KC_LSFT,  KC_NO,    KC_NO,    TO(0),
        KC_LCTL,  KC_NO,    KC_NO,    KC_SPACE
    )
};

void cycle_tab_color(void) {
    if (increasing) {
        green--;
        blue++;
        if (green == 0 && blue == 255) {
            increasing = false; // Reverse direction
        }
    } else {
        green++;
        blue--;
        if (green == 255 && blue == 0) {
            increasing = true; // Switch back
        }
    }
    led_colors[16][0]=0;
    led_colors[16][1]=green;
    led_colors[16][2]=blue;

    //rgb_matrix_set_color(16, 0, green, blue);// Update RGB lighting
}

bool rgb_matrix_indicators_user(void) {
    if (layer_state_is(0)) 
    {
        led_colors[13][0]=0;
        led_colors[13][1]=255;
        led_colors[13][2]=0; 
    }

    if (layer_state_is(1)) 
    {
        led_colors[13][0]=255;
        led_colors[13][1]=0;
        led_colors[13][2]=0; 
    }      

    if (layer_state_is(2)) 
    {
        led_colors[13][0]=0;
        led_colors[13][1]=0;
        led_colors[13][2]=255; 
    }      

    if (layer_state_is(3)) 
    {
        led_colors[13][0]=255;
        led_colors[13][1]=0;
        led_colors[13][2]=255; 
    }      
    
    
    for (int i = 0; i < 24; i++) {
        uint8_t r = DEFAULT_R, g = DEFAULT_G, b = DEFAULT_B;
        
        if (led_colors[i][0] || led_colors[i][1] || led_colors[i][2]) {
            r = (led_colors[i][0] * ledbright) / MAX_BRIGHTNESS;
            g = (led_colors[i][1] * ledbright) / MAX_BRIGHTNESS;
            b = (led_colors[i][2] * ledbright) / MAX_BRIGHTNESS;
        } else {
            r = (DEFAULT_R * ledbright) / MAX_BRIGHTNESS;
            g = (DEFAULT_G * ledbright) / MAX_BRIGHTNESS;
            b = (DEFAULT_B * ledbright) / MAX_BRIGHTNESS;
        }
        rgb_matrix_set_color(i, r, g, b);
    }
    cycle_tab_color();
    return true;
}


bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    if (record->event.pressed) {
        if (keycode == MACRO_BRIGHT_DOWN) { 
            if (ledbright > MIN_BRIGHTNESS) {
                ledbright -= 1;
            }
        } else if (keycode == MACRO_BRIGHT_UP) { 
            if (ledbright < MAX_BRIGHTNESS) {
                ledbright += 1;
            }
        }
    }
    return false;
}


I started by reading the stuff the @MJ1 had written Custom QMK firmware? - #14 by MJ1
been a while now but yeah it works for what I need :slight_smile:

That’s probably going to be helpful.

I did eventually find references to rgb_matrix_indicators_kb() which overrides the animations. For now, I have this, which is working as desired:

bool rgb_matrix_indicators_kb (void) {
if (host_keyboard_led_state().num_lock){
rgb_matrix_set_color(4, 0, rgb_matrix_get_val(), 0);
}
else {
rgb_matrix_set_color(4, rgb_matrix_get_val(), 0, 0);
}
return true;
}

This sets the Numlock Key to solid green while numlock is set, and red when not set, also keeps fairly in sync with the current brightness level.

I still think I’m missing something regarding the animations when trying to set arbitrary LEDs, since it appears to override anything I set explicitly (except for the above indicators function) But turning animations off just kills the LEDs entirely.