Howto RGB Layers

Very common question, very simple answer.
Comments and suggestions welcome
This commit is contained in:
xs5871 2022-10-01 14:34:55 +00:00 committed by Kyle Brown
parent 54a1d61a06
commit 91032e123f

View File

@ -68,3 +68,26 @@ keyboard.keymap = [
],
]
```
## Advanced Example
A common question is: "How do I change RGB background based on my active layer?"
Here is _one_ (simple) way of many to go about it.
```python
from kmk.modules.layers import Layers as _Layers
from kmk.extensions.rgb import RGB
rgb = RGB(...) # your RGB configuration goes here
keyboard.extensions.append(rgb)
class Layers(_Layers):
last_top_layer = 0
hues = (4, 20, 69)
def after_hid_send(keyboard):
if keyboard.active_layers[0] != self.last_top_layer:
self.last_top_layer = keyboard.active_layers[0]
rgb.set_hsv_fill(self.hues[self.last_top_layer], 255, 255)
keyboard.modules.append(Layers())
```