Advertisement
hakbraley

QMK Shifting Indicator LED

Oct 27th, 2022 (edited)
1,399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. /*  https://www.reddit.com/r/olkb/comments/yeojrc/qmk_help_my_keyboard_freezes_after_running_this/
  2.  *  Code to create a toggleable LED that continually shifts color when active.
  3.  *  You can work with RGB values directly instead of HSV, if you prefer.
  4.  *  Change "HSV ind_HSV" to "RGB ind_RGB" and delete the line with "hsv_to_rgb(ind_HSV);"
  5.  *  This can go into keymap.c
  6.  */
  7.  
  8. #define INDICATOR_LED_INDEX   15  // set the index of the LED you want to shift color
  9. #define INDICATOR_UPDATE_TIME 10  // set how often the indicator will change hue, in milliseconds
  10.  
  11. bool indicator_active = true;     // turns the indicator LED color shifting on and off
  12. HSV  ind_HSV = {HSV_BLUE};        // HSV variable to keep track of what color to set the LED to
  13. uint16_t last_ind_update = 0;     // timer to keep track of the last time the indicator was updated
  14.  
  15. void rgb_matrix_indicators_user() {
  16.     if (indicator_active) {
  17.         if (timer_elapsed(last_ind_update) > INDICATOR_UPDATE_TIME) {  // if it's time for the next LED update
  18.             last_ind_update = timer_read();  // update the LED timer
  19.  
  20.             // play with how you want to change the color each time here
  21.             ind_HSV.h++;  // increment h, the hue portion of ind_HSV for the indicator
  22.            
  23.  
  24.             RGB ind_RGB = hsv_to_rgb(ind_HSV);  // convert to RGB
  25.             rgb_matrix_set_color(15, ind_RGB.r, ind_RGB.g, ind_RGB.b);  // set color of indicator LED
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement