RGB Macropad Individual LED control via QMK

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: