You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

564 lines
35 KiB

  1. # RGB Lighting
  2. QMK has the ability to control RGB LEDs attached to your keyboard. This is commonly called *underglow*, due to the LEDs often being mounted on the bottom of the keyboard, producing a nice diffused effect when combined with a translucent case.
  3. ![Planck with RGB Underglow](https://raw.githubusercontent.com/qmk/qmk_firmware/3774a7fcdab5544fc787f4c200be05fcd417e31f/keyboards/planck/keymaps/yang/planck-with-rgb-underglow.jpg)
  4. Some keyboards come with RGB LEDs preinstalled. Others must have them installed after the fact. See the [Hardware Modification](#hardware-modification) section for information on adding RGB lighting to your keyboard.
  5. Currently QMK supports the following addressable LEDs (however, the white LED in RGBW variants is not supported):
  6. * WS2811, WS2812, WS2812B, WS2812C, etc.
  7. * SK6812, SK6812MINI, SK6805
  8. * APA102
  9. These LEDs are called "addressable" because instead of using a wire per color, each LED contains a small microchip that understands a special protocol sent over a single wire. The chip passes on the remaining data to the next LED, allowing them to be chained together. In this way, you can easily control the color of the individual LEDs.
  10. ## Usage
  11. On keyboards with onboard RGB LEDs, it is usually enabled by default. If it is not working for you, check that your `rules.mk` includes the following:
  12. ```make
  13. RGBLIGHT_ENABLE = yes
  14. ```
  15. For APA102 LEDs, add the following to your `rules.mk`:
  16. ```make
  17. RGBLIGHT_ENABLE = yes
  18. RGBLIGHT_DRIVER = APA102
  19. ```
  20. At minimum you must define the data pin your LED strip is connected to, and the number of LEDs in the strip, in your `config.h`. For APA102 LEDs, you must also define the clock pin. If your keyboard has onboard RGB LEDs, and you are simply creating a keymap, you usually won't need to modify these.
  21. |Define |Description |
  22. |---------------|---------------------------------------------------------------------------------------------------------|
  23. |`RGB_DI_PIN` |The pin connected to the data pin of the LEDs |
  24. |`RGB_CI_PIN` |The pin connected to the clock pin of the LEDs (APA102 only) |
  25. |`RGBLED_NUM` |The number of LEDs connected |
  26. |`RGBLED_SPLIT` |(Optional) For split keyboards, the number of LEDs connected on each half directly wired to `RGB_DI_PIN` |
  27. Then you should be able to use the keycodes below to change the RGB lighting to your liking.
  28. ### Color Selection
  29. QMK uses [Hue, Saturation, and Value](https://en.wikipedia.org/wiki/HSL_and_HSV) to select colors rather than RGB. The color wheel below demonstrates how this works.
  30. <img src="gitbook/images/color-wheel.svg" alt="HSV Color Wheel" width="250"/>
  31. Changing the **Hue** cycles around the circle.<br>
  32. Changing the **Saturation** moves between the inner and outer sections of the wheel, affecting the intensity of the color.<br>
  33. Changing the **Value** sets the overall brightness.<br>
  34. ![QMK Color Wheel with HSV Values](https://i.imgur.com/vkYVo66.jpg)
  35. ## Keycodes
  36. |Key |Aliases |Description |
  37. |-------------------|----------|--------------------------------------------------------------------|
  38. |`RGB_TOG` | |Toggle RGB lighting on or off |
  39. |`RGB_MODE_FORWARD` |`RGB_MOD` |Cycle through modes, reverse direction when Shift is held |
  40. |`RGB_MODE_REVERSE` |`RGB_RMOD`|Cycle through modes in reverse, forward direction when Shift is held|
  41. |`RGB_HUI` | |Increase hue, decrease hue when Shift is held |
  42. |`RGB_HUD` | |Decrease hue, increase hue when Shift is held |
  43. |`RGB_SAI` | |Increase saturation, decrease saturation when Shift is held |
  44. |`RGB_SAD` | |Decrease saturation, increase saturation when Shift is held |
  45. |`RGB_VAI` | |Increase value (brightness), decrease value when Shift is held |
  46. |`RGB_VAD` | |Decrease value (brightness), increase value when Shift is held |
  47. |`RGB_MODE_PLAIN` |`RGB_M_P `|Static (no animation) mode |
  48. |`RGB_MODE_BREATHE` |`RGB_M_B` |Breathing animation mode |
  49. |`RGB_MODE_RAINBOW` |`RGB_M_R` |Rainbow animation mode |
  50. |`RGB_MODE_SWIRL` |`RGB_M_SW`|Swirl animation mode |
  51. |`RGB_MODE_SNAKE` |`RGB_M_SN`|Snake animation mode |
  52. |`RGB_MODE_KNIGHT` |`RGB_M_K` |"Knight Rider" animation mode |
  53. |`RGB_MODE_XMAS` |`RGB_M_X` |Christmas animation mode |
  54. |`RGB_MODE_GRADIENT`|`RGB_M_G` |Static gradient animation mode |
  55. |`RGB_MODE_RGBTEST` |`RGB_M_T` |Red, Green, Blue test animation mode |
  56. |`RGB_MODE_TWINKLE` |`RGB_M_TW`|Twinkle animation mode |
  57. !> By default, if you have both the RGB Light and the [RGB Matrix](feature_rgb_matrix.md) feature enabled, these keycodes will work for both features, at the same time. You can disable the keycode functionality by defining the `*_DISABLE_KEYCODES` option for the specific feature.
  58. ## Configuration
  59. Your RGB lighting can be configured by placing these `#define`s in your `config.h`:
  60. |Define |Default |Description |
  61. |---------------------------|----------------------------|---------------------------------------------------------------------------------------------------------------------------|
  62. |`RGBLIGHT_HUE_STEP` |`10` |The number of steps to cycle through the hue by |
  63. |`RGBLIGHT_SAT_STEP` |`17` |The number of steps to increment the saturation by |
  64. |`RGBLIGHT_VAL_STEP` |`17` |The number of steps to increment the brightness by |
  65. |`RGBLIGHT_LIMIT_VAL` |`255` |The maximum brightness level |
  66. |`RGBLIGHT_SLEEP` |*Not defined* |If defined, the RGB lighting will be switched off when the host goes to sleep |
  67. |`RGBLIGHT_SPLIT` |*Not defined* |If defined, synchronization functionality for split keyboards is added |
  68. |`RGBLIGHT_DISABLE_KEYCODES`|*Not defined* |If defined, disables the ability to control RGB Light from the keycodes. You must use code functions to control the feature|
  69. |`RGBLIGHT_DEFAULT_MODE` |`RGBLIGHT_MODE_STATIC_LIGHT`|The default mode to use upon clearing the EEPROM |
  70. |`RGBLIGHT_DEFAULT_HUE` |`0` (red) |The default hue to use upon clearing the EEPROM |
  71. |`RGBLIGHT_DEFAULT_SAT` |`UINT8_MAX` (255) |The default saturation to use upon clearing the EEPROM |
  72. |`RGBLIGHT_DEFAULT_VAL` |`RGBLIGHT_LIMIT_VAL` |The default value (brightness) to use upon clearing the EEPROM |
  73. |`RGBLIGHT_DEFAULT_SPD` |`0` |The default speed to use upon clearing the EEPROM |
  74. ## Effects and Animations
  75. Not only can this lighting be whatever color you want,
  76. if `RGBLIGHT_EFFECT_xxxx` or `RGBLIGHT_ANIMATIONS` is defined, you also have a number of animation modes at your disposal:
  77. |Mode number symbol |Additional number |Description |
  78. |-----------------------------|-------------------|---------------------------------------|
  79. |`RGBLIGHT_MODE_STATIC_LIGHT` | *None* |Solid color (this mode is always enabled) |
  80. |`RGBLIGHT_MODE_BREATHING` | 0,1,2,3 |Solid color breathing |
  81. |`RGBLIGHT_MODE_RAINBOW_MOOD` | 0,1,2 |Cycling rainbow |
  82. |`RGBLIGHT_MODE_RAINBOW_SWIRL`| 0,1,2,3,4,5 |Swirling rainbow |
  83. |`RGBLIGHT_MODE_SNAKE` | 0,1,2,3,4,5 |Snake |
  84. |`RGBLIGHT_MODE_KNIGHT` | 0,1,2 |Knight |
  85. |`RGBLIGHT_MODE_CHRISTMAS` | *None* |Christmas |
  86. |`RGBLIGHT_MODE_STATIC_GRADIENT`| 0,1,..,9 |Static gradient |
  87. |`RGBLIGHT_MODE_RGB_TEST` | *None* |RGB Test |
  88. |`RGBLIGHT_MODE_ALTERNATING` | *None* |Alternating |
  89. |`RGBLIGHT_MODE_TWINKLE` | 0,1,2,3,4,5 |Twinkle |
  90. Check out [this video](https://youtube.com/watch?v=VKrpPAHlisY) for a demonstration.
  91. Note: For versions older than 0.6.117, The mode numbers were written directly. In `quantum/rgblight/rgblight.h` there is a contrast table between the old mode number and the current symbol.
  92. ### Effect and Animation Toggles
  93. Use these defines to add or remove animations from the firmware. When you are running low on flash space, it can be helpful to disable animations you are not using.
  94. |Define |Default |Description |
  95. |------------------------------------|-------------|-------------------------------------------------------------------------|
  96. |`RGBLIGHT_ANIMATIONS` |*Not defined*|Enable all additional animation modes. |
  97. |`RGBLIGHT_EFFECT_ALTERNATING` |*Not defined*|Enable alternating animation mode. |
  98. |`RGBLIGHT_EFFECT_BREATHING` |*Not defined*|Enable breathing animation mode. |
  99. |`RGBLIGHT_EFFECT_CHRISTMAS` |*Not defined*|Enable christmas animation mode. |
  100. |`RGBLIGHT_EFFECT_KNIGHT` |*Not defined*|Enable knight animation mode. |
  101. |`RGBLIGHT_EFFECT_RAINBOW_MOOD` |*Not defined*|Enable rainbow mood animation mode. |
  102. |`RGBLIGHT_EFFECT_RAINBOW_SWIRL` |*Not defined*|Enable rainbow swirl animation mode. |
  103. |`RGBLIGHT_EFFECT_RGB_TEST` |*Not defined*|Enable RGB test animation mode. |
  104. |`RGBLIGHT_EFFECT_SNAKE` |*Not defined*|Enable snake animation mode. |
  105. |`RGBLIGHT_EFFECT_STATIC_GRADIENT` |*Not defined*|Enable static gradient mode. |
  106. |`RGBLIGHT_EFFECT_TWINKLE` |*Not defined*|Enable twinkle animation mode. |
  107. ### Effect and Animation Settings
  108. The following options are used to tweak the various animations:
  109. |Define |Default |Description |
  110. |------------------------------------|-------------|-----------------------------------------------------------------------------------------------|
  111. |`RGBLIGHT_EFFECT_BREATHE_CENTER` |*Not defined*|If defined, used to calculate the curve for the breathing animation. Valid values are 1.0 to 2.7 |
  112. |`RGBLIGHT_EFFECT_BREATHE_MAX` |`255` |The maximum brightness for the breathing mode. Valid values are 1 to 255 |
  113. |`RGBLIGHT_EFFECT_CHRISTMAS_INTERVAL`|`40` |How long (in milliseconds) to wait between animation steps for the "Christmas" animation |
  114. |`RGBLIGHT_EFFECT_CHRISTMAS_STEP` |`2` |The number of LEDs to group the red/green colors by for the "Christmas" animation |
  115. |`RGBLIGHT_EFFECT_KNIGHT_LED_NUM` |`RGBLED_NUM` |The number of LEDs to have the "Knight" animation travel |
  116. |`RGBLIGHT_EFFECT_KNIGHT_LENGTH` |`3` |The number of LEDs to light up for the "Knight" animation |
  117. |`RGBLIGHT_EFFECT_KNIGHT_OFFSET` |`0` |The number of LEDs to start the "Knight" animation from the start of the strip by |
  118. |`RGBLIGHT_RAINBOW_SWIRL_RANGE` |`255` |Range adjustment for the rainbow swirl effect to get different swirls |
  119. |`RGBLIGHT_EFFECT_SNAKE_LENGTH` |`4` |The number of LEDs to light up for the "Snake" animation |
  120. |`RGBLIGHT_EFFECT_TWINKLE_LIFE` |`200` |Adjusts how quickly each LED brightens and dims when twinkling (in animation steps) |
  121. |`RGBLIGHT_EFFECT_TWINKLE_PROBABILITY`|`1/127` |Adjusts how likely each LED is to twinkle (on each animation step) |
  122. ### Example Usage to Reduce Memory Footprint
  123. 1. Remove `RGBLIGHT_ANIMATIONS` from `config.h`.
  124. 1. Selectively add the animations you want to enable. The following would enable two animations and save about 4KiB:
  125. ```diff
  126. #undef RGBLED_NUM
  127. -#define RGBLIGHT_ANIMATIONS
  128. +#define RGBLIGHT_EFFECT_STATIC_GRADIENT
  129. +#define RGBLIGHT_EFFECT_RAINBOW_SWIRL
  130. #define RGBLED_NUM 12
  131. #define RGBLIGHT_HUE_STEP 8
  132. #define RGBLIGHT_SAT_STEP 8
  133. ```
  134. ### Animation Speed
  135. You can also modify the speeds that the different modes animate at:
  136. Here is a quick demo on Youtube (with NPKC KC60) (https://www.youtube.com/watch?v=VKrpPAHlisY).
  137. ```c
  138. // How long (in milliseconds) to wait between animation steps for each of the "Solid color breathing" animations
  139. const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5};
  140. // How long (in milliseconds) to wait between animation steps for each of the "Cycling rainbow" animations
  141. const uint8_t RGBLED_RAINBOW_MOOD_INTERVALS[] PROGMEM = {120, 60, 30};
  142. // How long (in milliseconds) to wait between animation steps for each of the "Swirling rainbow" animations
  143. const uint8_t RGBLED_RAINBOW_SWIRL_INTERVALS[] PROGMEM = {100, 50, 20};
  144. // How long (in milliseconds) to wait between animation steps for each of the "Snake" animations
  145. const uint8_t RGBLED_SNAKE_INTERVALS[] PROGMEM = {100, 50, 20};
  146. // How long (in milliseconds) to wait between animation steps for each of the "Knight" animations
  147. const uint8_t RGBLED_KNIGHT_INTERVALS[] PROGMEM = {127, 63, 31};
  148. // How long (in milliseconds) to wait between animation steps for each of the "Twinkle" animations
  149. const uint8_t RGBLED_TWINKLE_INTERVALS[] PROGMEM = {50, 25, 10};
  150. // These control which hues are selected for each of the "Static gradient" modes
  151. const uint8_t RGBLED_GRADIENT_RANGES[] PROGMEM = {255, 170, 127, 85, 64};
  152. ```
  153. ## Lighting Layers
  154. ?> **Note:** Lighting Layers is an RGB Light feature, it will not work for RGB Matrix. See [RGB Matrix Indicators](feature_rgb_matrix.md?indicators) for details on how to do so.
  155. By including `#define RGBLIGHT_LAYERS` in your `config.h` file you can enable lighting layers. These make
  156. it easy to use your underglow LEDs as status indicators to show which keyboard layer is currently active, or the state of caps lock, all without disrupting any animations. [Here's a video](https://youtu.be/uLGE1epbmdY) showing an example of what you can do.
  157. ### Defining Lighting Layers :id=defining-lighting-layers
  158. By default, 8 layers are possible. This can be expanded to as many as 32 by overriding the definition of `RGBLIGHT_MAX_LAYERS` in `config.h` (e.g. `#define RGBLIGHT_MAX_LAYERS 32`). Please note, if you use a split keyboard, you will need to flash both sides of the split after changing this. Also, increasing the maximum will increase the firmware size, and will slow sync on split keyboards.
  159. To define a layer, we modify `keymap.c` to list the LED ranges and the colors we want to overlay on them using an array of `rgblight_segment_t` using the `RGBLIGHT_LAYER_SEGMENTS` macro. We can define multiple layers and enable/disable them independently:
  160. ```c
  161. // Light LEDs 6 to 9 and 12 to 15 red when caps lock is active. Hard to ignore!
  162. const rgblight_segment_t PROGMEM my_capslock_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  163. {6, 4, HSV_RED}, // Light 4 LEDs, starting with LED 6
  164. {12, 4, HSV_RED} // Light 4 LEDs, starting with LED 12
  165. );
  166. // Light LEDs 9 & 10 in cyan when keyboard layer 1 is active
  167. const rgblight_segment_t PROGMEM my_layer1_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  168. {9, 2, HSV_CYAN}
  169. );
  170. // Light LEDs 11 & 12 in purple when keyboard layer 2 is active
  171. const rgblight_segment_t PROGMEM my_layer2_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  172. {11, 2, HSV_PURPLE}
  173. );
  174. // Light LEDs 13 & 14 in green when keyboard layer 3 is active
  175. const rgblight_segment_t PROGMEM my_layer3_layer[] = RGBLIGHT_LAYER_SEGMENTS(
  176. {13, 2, HSV_GREEN}
  177. );
  178. // etc..
  179. ```
  180. We combine these layers into an array using the `RGBLIGHT_LAYERS_LIST` macro, and assign it to the `rgblight_layers` variable during keyboard setup. Note that you can only define up to 8 lighting layers. Any extra layers will be ignored. Since the different lighting layers overlap, the order matters in the array, with later layers taking precedence:
  181. ```c
  182. // Now define the array of layers. Later layers take precedence
  183. const rgblight_segment_t* const PROGMEM my_rgb_layers[] = RGBLIGHT_LAYERS_LIST(
  184. my_capslock_layer,
  185. my_layer1_layer, // Overrides caps lock layer
  186. my_layer2_layer, // Overrides other layers
  187. my_layer3_layer // Overrides other layers
  188. );
  189. void keyboard_post_init_user(void) {
  190. // Enable the LED layers
  191. rgblight_layers = my_rgb_layers;
  192. }
  193. ```
  194. Note: For split keyboards with two controllers, both sides need to be flashed when updating the contents of rgblight_layers.
  195. ### Enabling and disabling lighting layers :id=enabling-lighting-layers
  196. Everything above just configured the definition of each lighting layer.
  197. We can now enable and disable the lighting layers whenever the state of the keyboard changes:
  198. ```c
  199. bool led_update_user(led_t led_state) {
  200. rgblight_set_layer_state(0, led_state.caps_lock);
  201. return true;
  202. }
  203. layer_state_t default_layer_state_set_user(layer_state_t state) {
  204. rgblight_set_layer_state(1, layer_state_cmp(state, _DVORAK));
  205. return state;
  206. }
  207. layer_state_t layer_state_set_user(layer_state_t state) {
  208. rgblight_set_layer_state(2, layer_state_cmp(state, _FN));
  209. rgblight_set_layer_state(3, layer_state_cmp(state, _ADJUST));
  210. return state;
  211. }
  212. ```
  213. ### Lighting layer blink :id=lighting-layer-blink
  214. By including `#define RGBLIGHT_LAYER_BLINK` in your `config.h` file you can turn a lighting
  215. layer on for a specified duration. Once the specified number of milliseconds has elapsed
  216. the layer will be turned off. This is useful, e.g., if you want to acknowledge some
  217. action (e.g. toggling some setting):
  218. ```c
  219. const rgblight_segment_t PROGMEM _yes_layer[] = RGBLIGHT_LAYER_SEGMENTS( {9, 6, HSV_GREEN} );
  220. const rgblight_segment_t PROGMEM _no_layer[] = RGBLIGHT_LAYER_SEGMENTS( {9, 6, HSV_RED} );
  221. const rgblight_segment_t* const PROGMEM _rgb_layers[] =
  222. RGBLIGHT_LAYERS_LIST( _yes_layer, _no_layer );
  223. void keyboard_post_init_user(void) {
  224. rgblight_layers = _rgb_layers;
  225. }
  226. // Note we user post_process_record_user because we want the state
  227. // after the flag has been flipped...
  228. void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
  229. switch (keycode) {
  230. case DEBUG:
  231. rgblight_blink_layer(debug_enable ? 0 : 1, 500);
  232. break;
  233. case NK_TOGG:
  234. case NK_ON:
  235. case NK_OFF:
  236. rgblight_blink_layer(keymap_config.nkro ? 0 : 1, 500);
  237. break;
  238. }
  239. }
  240. ```
  241. You can also use `rgblight_blink_layer_repeat` to specify the amount of times the layer is supposed to blink. Using the layers from above,
  242. ```c
  243. void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
  244. switch (keycode) {
  245. case DEBUG:
  246. rgblight_blink_layer_repeat(debug_enable ? 0 : 1, 200, 3);
  247. break;
  248. }
  249. }
  250. ```
  251. would turn the layer 0 (or 1) on and off again three times when `DEBUG` is pressed.
  252. ### Overriding RGB Lighting on/off status
  253. Normally lighting layers are not shown when RGB Lighting is disabled (e.g. with `RGB_TOG` keycode). If you would like lighting layers to work even when the RGB Lighting is otherwise off, add `#define RGBLIGHT_LAYERS_OVERRIDE_RGB_OFF` to your `config.h`.
  254. ### Retain brightness
  255. Usually lighting layers apply their configured brightness once activated. If you would like lighting layers to retain the currently used brightness (as returned by `rgblight_get_val()`), add `#define RGBLIGHT_LAYERS_RETAIN_VAL` to your `config.h`.
  256. ## Functions
  257. If you need to change your RGB lighting in code, for example in a macro to change the color whenever you switch layers, QMK provides a set of functions to assist you. See [`rgblight.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/rgblight/rgblight.h) for the full list, but the most commonly used functions include:
  258. ### Utility Functions
  259. |Function |Description |
  260. |--------------------------------------------|-------------------------------------------------------------------|
  261. |`sethsv(hue, sat, val, ledbuf)` |Set ledbuf to the given HSV value |
  262. |`sethsv_raw(hue, sat, val, ledbuf)` |Set ledbuf to the given HSV value without RGBLIGHT_LIMIT_VAL check |
  263. |`setrgb(r, g, b, ledbuf)` |Set ledbuf to the given RGB value where `r`/`g`/`b` |
  264. ### Low level Functions
  265. |Function |Description |
  266. |--------------------------------------------|-------------------------------------------|
  267. |`rgblight_set()` |Flash out led buffers to LEDs |
  268. |`rgblight_set_clipping_range(pos, num)` |Set clipping Range. see [Clipping Range](#clipping-range) |
  269. Example:
  270. ```c
  271. sethsv(HSV_WHITE, (LED_TYPE *)&led[0]); // led 0
  272. sethsv(HSV_RED, (LED_TYPE *)&led[1]); // led 1
  273. sethsv(HSV_GREEN, (LED_TYPE *)&led[2]); // led 2
  274. rgblight_set(); // Utility functions do not call rgblight_set() automatically, so they need to be called explicitly.
  275. ```
  276. ### Effects and Animations Functions
  277. #### effect range setting
  278. |Function |Description |
  279. |--------------------------------------------|------------------|
  280. |`rgblight_set_effect_range(pos, num)` |Set Effects Range |
  281. #### direct operation
  282. |Function |Description |
  283. |--------------------------------------------|-------------|
  284. |`rgblight_setrgb_at(r, g, b, index)` |Set a single LED to the given RGB value, where `r`/`g`/`b` are between 0 and 255 and `index` is between 0 and `RGBLED_NUM` (not written to EEPROM) |
  285. |`rgblight_sethsv_at(h, s, v, index)` |Set a single LED to the given HSV value, where `h`/`s`/`v` are between 0 and 255, and `index` is between 0 and `RGBLED_NUM` (not written to EEPROM) |
  286. |`rgblight_setrgb_range(r, g, b, start, end)`|Set a continuous range of LEDs to the given RGB value, where `r`/`g`/`b` are between 0 and 255 and `start`(included) and `stop`(excluded) are between 0 and `RGBLED_NUM` (not written to EEPROM)|
  287. |`rgblight_sethsv_range(h, s, v, start, end)`|Set a continuous range of LEDs to the given HSV value, where `h`/`s`/`v` are between 0 and 255, and `start`(included) and `stop`(excluded) are between 0 and `RGBLED_NUM` (not written to EEPROM)|
  288. |`rgblight_setrgb(r, g, b)` |Set effect range LEDs to the given RGB value where `r`/`g`/`b` are between 0 and 255 (not written to EEPROM) |
  289. |`rgblight_setrgb_master(r, g, b)` |Set the LEDs on the master side to the given RGB value, where `r`/`g`/`b` are between 0 and 255 (not written to EEPROM) |
  290. |`rgblight_setrgb_slave(r, g, b)` |Set the LEDs on the slave side to the given RGB value, where `r`/`g`/`b` are between 0 and 255 (not written to EEPROM) |
  291. |`rgblight_sethsv_master(h, s, v)` |Set the LEDs on the master side to the given HSV value, where `h`/`s`/`v` are between 0 and 255 (not written to EEPROM) |
  292. |`rgblight_sethsv_slave(h, s, v)` |Set the LEDs on the slave side to the given HSV value, where `h`/`s`/`v` are between 0 and 255 (not written to EEPROM) |
  293. Example:
  294. ```c
  295. rgblight_sethsv_at(HSV_WHITE, 0); // led 0
  296. rgblight_sethsv_at(HSV_RED, 1); // led 1
  297. rgblight_sethsv_at(HSV_GREEN, 2); // led 2
  298. // The above functions automatically calls rgblight_set(), so there is no need to call it explicitly.
  299. // Note that it is inefficient to call repeatedly.
  300. ```
  301. #### effect mode change
  302. |Function |Description |
  303. |--------------------------------------------|-------------|
  304. |`rgblight_mode(x)` |Set the mode, if RGB animations are enabled |
  305. |`rgblight_mode_noeeprom(x)` |Set the mode, if RGB animations are enabled (not written to EEPROM) |
  306. |`rgblight_step()` |Change the mode to the next RGB animation in the list of enabled RGB animations |
  307. |`rgblight_step_noeeprom()` |Change the mode to the next RGB animation in the list of enabled RGB animations (not written to EEPROM) |
  308. |`rgblight_step_reverse()` |Change the mode to the previous RGB animation in the list of enabled RGB animations |
  309. |`rgblight_step_reverse_noeeprom()` |Change the mode to the previous RGB animation in the list of enabled RGB animations (not written to EEPROM) |
  310. |`rgblight_reload_from_eeprom()` |Reload the effect configuration (enabled, mode and color) from EEPROM |
  311. #### effects mode disable/enable
  312. |Function |Description |
  313. |--------------------------------------------|-------------|
  314. |`rgblight_toggle()` |Toggle effect range LEDs between on and off |
  315. |`rgblight_toggle_noeeprom()` |Toggle effect range LEDs between on and off (not written to EEPROM) |
  316. |`rgblight_enable()` |Turn effect range LEDs on, based on their previous state |
  317. |`rgblight_enable_noeeprom()` |Turn effect range LEDs on, based on their previous state (not written to EEPROM) |
  318. |`rgblight_disable()` |Turn effect range LEDs off |
  319. |`rgblight_disable_noeeprom()` |Turn effect range LEDs off (not written to EEPROM) |
  320. #### hue, sat, val change
  321. |Function |Description |
  322. |--------------------------------------------|-------------|
  323. |`rgblight_increase_hue()` |Increase the hue for effect range LEDs. This wraps around at maximum hue |
  324. |`rgblight_increase_hue_noeeprom()` |Increase the hue for effect range LEDs. This wraps around at maximum hue (not written to EEPROM) |
  325. |`rgblight_decrease_hue()` |Decrease the hue for effect range LEDs. This wraps around at minimum hue |
  326. |`rgblight_decrease_hue_noeeprom()` |Decrease the hue for effect range LEDs. This wraps around at minimum hue (not written to EEPROM) |
  327. |`rgblight_increase_sat()` |Increase the saturation for effect range LEDs. This stops at maximum saturation |
  328. |`rgblight_increase_sat_noeeprom()` |Increase the saturation for effect range LEDs. This stops at maximum saturation (not written to EEPROM) |
  329. |`rgblight_decrease_sat()` |Decrease the saturation for effect range LEDs. This stops at minimum saturation |
  330. |`rgblight_decrease_sat_noeeprom()` |Decrease the saturation for effect range LEDs. This stops at minimum saturation (not written to EEPROM) |
  331. |`rgblight_increase_val()` |Increase the value for effect range LEDs. This stops at maximum value |
  332. |`rgblight_increase_val_noeeprom()` |Increase the value for effect range LEDs. This stops at maximum value (not written to EEPROM) |
  333. |`rgblight_decrease_val()` |Decrease the value for effect range LEDs. This stops at minimum value |
  334. |`rgblight_decrease_val_noeeprom()` |Decrease the value for effect range LEDs. This stops at minimum value (not written to EEPROM) |
  335. |`rgblight_sethsv(h, s, v)` |Set effect range LEDs to the given HSV value where `h`/`s`/`v` are between 0 and 255 |
  336. |`rgblight_sethsv_noeeprom(h, s, v)` |Set effect range LEDs to the given HSV value where `h`/`s`/`v` are between 0 and 255 (not written to EEPROM) |
  337. #### Speed functions
  338. |Function |Description |
  339. |--------------------------------------------|-------------|
  340. |`rgblight_increase_speed()` |Increases the animation speed |
  341. |`rgblight_increase_speed_noeeprom()` |Increases the animation speed (not written to EEPROM) |
  342. |`rgblight_decrease_speed()` |Decreases the animation speed |
  343. |`rgblight_decrease_speed_noeeprom()` |Decreases the animation speed (not written to EEPROM) |
  344. |`rgblight_set_speed()` |Sets the speed. Value is between 0 and 255 |
  345. |`rgblight_set_speed_noeeprom()` |Sets the speed. Value is between 0 and 255 (not written to EEPROM) |
  346. #### layer functions
  347. |Function |Description |
  348. |--------------------------------------------|-------------|
  349. |`rgblight_get_layer_state(i)` |Returns `true` if lighting layer `i` is enabled |
  350. |`rgblight_set_layer_state(i, is_on)` |Enable or disable lighting layer `i` based on value of `bool is_on` |
  351. #### query
  352. |Function |Description |
  353. |-----------------------|---------------------------|
  354. |`rgblight_is_enabled()`|Gets current on/off status |
  355. |`rgblight_get_mode()` |Gets current mode |
  356. |`rgblight_get_hue()` |Gets current hue |
  357. |`rgblight_get_sat()` |Gets current sat |
  358. |`rgblight_get_val()` |Gets current val |
  359. |`rgblight_get_speed()` |Gets current speed |
  360. ## Colors
  361. These are shorthands to popular colors. The `RGB` ones can be passed to the `setrgb` functions, while the `HSV` ones to the `sethsv` functions.
  362. |RGB |HSV |
  363. |---------------------|---------------------|
  364. |`RGB_AZURE` |`HSV_AZURE` |
  365. |`RGB_BLACK`/`RGB_OFF`|`HSV_BLACK`/`HSV_OFF`|
  366. |`RGB_BLUE` |`HSV_BLUE` |
  367. |`RGB_CHARTREUSE` |`HSV_CHARTREUSE` |
  368. |`RGB_CORAL` |`HSV_CORAL` |
  369. |`RGB_CYAN` |`HSV_CYAN` |
  370. |`RGB_GOLD` |`HSV_GOLD` |
  371. |`RGB_GOLDENROD` |`HSV_GOLDENROD` |
  372. |`RGB_GREEN` |`HSV_GREEN` |
  373. |`RGB_MAGENTA` |`HSV_MAGENTA` |
  374. |`RGB_ORANGE` |`HSV_ORANGE` |
  375. |`RGB_PINK` |`HSV_PINK` |
  376. |`RGB_PURPLE` |`HSV_PURPLE` |
  377. |`RGB_RED` |`HSV_RED` |
  378. |`RGB_SPRINGGREEN` |`HSV_SPRINGGREEN` |
  379. |`RGB_TEAL` |`HSV_TEAL` |
  380. |`RGB_TURQUOISE` |`HSV_TURQUOISE` |
  381. |`RGB_WHITE` |`HSV_WHITE` |
  382. |`RGB_YELLOW` |`HSV_YELLOW` |
  383. ```c
  384. rgblight_setrgb(RGB_ORANGE);
  385. rgblight_sethsv_noeeprom(HSV_GREEN);
  386. rgblight_setrgb_at(RGB_GOLD, 3);
  387. rgblight_sethsv_range(HSV_WHITE, 0, 6);
  388. ```
  389. These are defined in [`color.h`](https://github.com/qmk/qmk_firmware/blob/master/quantum/color.h). Feel free to add to this list!
  390. ## Changing the order of the LEDs
  391. If you want to make the logical order of LEDs different from the electrical connection order, you can do this by defining the `RGBLIGHT_LED_MAP` macro in your `config.h`.
  392. Normally, the contents of the LED buffer are output to the LEDs in the same order.
  393. <img src="https://user-images.githubusercontent.com/2170248/55743718-01866c80-5a6e-11e9-8134-25419928327a.JPG" alt="simple dicrect" width="50%"/>
  394. By defining `RGBLIGHT_LED_MAP` as in the example below, you can specify the LED with addressing in reverse order of the electrical connection order.
  395. ```c
  396. // config.h
  397. #define RGBLED_NUM 4
  398. #define RGBLIGHT_LED_MAP { 3, 2, 1, 0 }
  399. ```
  400. <img src="https://user-images.githubusercontent.com/2170248/55743725-08ad7a80-5a6e-11e9-83ed-126a2b0209fc.JPG" alt="simple mapped" width="50%"/>
  401. For keyboards that use the RGB LEDs as a backlight for each key, you can also define it as in the example below.
  402. ```c
  403. // config.h
  404. #define RGBLED_NUM 30
  405. /* RGB LED Conversion macro from physical array to electric array */
  406. #define LED_LAYOUT( \
  407. L00, L01, L02, L03, L04, L05, \
  408. L10, L11, L12, L13, L14, L15, \
  409. L20, L21, L22, L23, L24, L25, \
  410. L30, L31, L32, L33, L34, L35, \
  411. L40, L41, L42, L43, L44, L45 ) \
  412. { \
  413. L05, L04, L03, L02, L01, L00, \
  414. L10, L11, L12, L13, L14, L15, \
  415. L25, L24, L23, L22, L21, L20, \
  416. L30, L31, L32, L33, L34, L35, \
  417. L46, L45, L44, L43, L42, L41 \
  418. }
  419. /* RGB LED logical order map */
  420. /* Top->Bottom, Right->Left */
  421. #define RGBLIGHT_LED_MAP LED_LAYOUT( \
  422. 25, 20, 15, 10, 5, 0, \
  423. 26, 21, 16, 11, 6, 1, \
  424. 27, 22, 17, 12, 7, 2, \
  425. 28, 23, 18, 13, 8, 3, \
  426. 29, 24, 19, 14, 9, 4 )
  427. ```
  428. ## Clipping Range
  429. Using the `rgblight_set_clipping_range()` function, you can prepare more buffers than the actual number of LEDs, and output some of the buffers to the LEDs. This is useful if you want the split keyboard to treat left and right LEDs as logically contiguous.
  430. You can set the Clipping Range by executing the following code.
  431. ```c
  432. // some source
  433. rgblight_set_clipping_range(3, 4);
  434. ```
  435. <img src="https://user-images.githubusercontent.com/2170248/55743785-2bd82a00-5a6e-11e9-9d4b-1b4ffaf4932b.JPG" alt="clip direct" width="70%"/>
  436. In addition to setting the Clipping Range, you can use `RGBLIGHT_LED_MAP` together.
  437. ```c
  438. // config.h
  439. #define RGBLED_NUM 8
  440. #define RGBLIGHT_LED_MAP { 7, 6, 5, 4, 3, 2, 1, 0 }
  441. // some soruce
  442. rgblight_set_clipping_range(3, 4);
  443. ```
  444. <img src="https://user-images.githubusercontent.com/2170248/55743747-119e4c00-5a6e-11e9-91e5-013203ffae8a.JPG" alt="clip mapped" width="70%"/>
  445. ## Hardware Modification
  446. If your keyboard lacks onboard underglow LEDs, you may often be able to solder on an RGB LED strip yourself. You will need to find an unused pin to wire to the data pin of your LED strip. Some keyboards may break out unused pins from the MCU to make soldering easier. The other two pins, VCC and GND, must also be connected to the appropriate power pins.