feat(extensions): most of the extensions implementation, by kdb424
This commit is contained in:
95
docs/rgb.md
95
docs/rgb.md
@@ -1,16 +1,18 @@
|
||||
# RGB/Underglow/Neopixel
|
||||
Want your keyboard to shine? Add some lights!
|
||||
This does require the neopixel library from Adafruit. This can be downloaded [here](https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/6e35cd2b40575a20e2904b096508325cef4a71d3/neopixel.py).
|
||||
It is part of the [Adafruit CircuitPython Bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle).
|
||||
|
||||
## Circuitpython
|
||||
If not running KMKpython, this does require the neopixel library from Adafruit.
|
||||
This can be downloaded
|
||||
[here](https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel/blob/6e35cd2b40575a20e2904b096508325cef4a71d3/neopixel.py).
|
||||
It is part of the [Adafruit CircuitPython Bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle).
|
||||
Simply put this in the "root" of your circuitpython device. If unsure, it's the folder with main.py in it, and should be the first folder you see when you open the device.
|
||||
|
||||
Currently we support the following addressable LEDs:
|
||||
|
||||
* WS2811, WS2812, WS2812B, WS2812C, etc.
|
||||
* SK6812, SK6812MINI, SK6805
|
||||
* All neopixels
|
||||
|
||||
|
||||
### Color Selection
|
||||
|
||||
KMK 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.
|
||||
@@ -19,6 +21,16 @@ Changing the **Hue** cycles around the circle.
|
||||
Changing the **Saturation** moves between the inner and outer sections of the wheel, affecting the intensity of the color.
|
||||
Changing the **Value** sets the overall brightness.
|
||||
|
||||
## Enabling the extention
|
||||
The only required values that you need to give the RGB extention would be the pixel pin, and the number of pixels/LED's. If using a split keyboard, this number is per side, and not the total of both sides.
|
||||
```python
|
||||
from kmk.extensions.RGB import RGB
|
||||
from kb import rgb_pixel_pin # This can be imported or defined manually
|
||||
|
||||
rgb_ext = RGB(pixel_pin=rgb_pixel_pin, num_pixels=27)
|
||||
keyboard.extensions.append(rgb_ext)
|
||||
```
|
||||
|
||||
## [Keycodes]
|
||||
|
||||
|Key |Aliases |Description |
|
||||
@@ -92,55 +104,46 @@ If you want to create your own animations, or for example, change the lighting i
|
||||
|`keyboard.pixels.animation_mode` |`static` |This can be changed to any modes included, or to something custom for user animations. Any string is valid |
|
||||
|`keyboard.pixels.animation_speed` |`1` |Increases animation speed of most animations. Recommended 1-5, Maximum 10. |
|
||||
|
||||
```python
|
||||
from kmk.extentions.rgb import AnimationModes
|
||||
rgb_ext = RGB(pixel_pin=rgb_pixel_pin,
|
||||
num_pixels=27
|
||||
num_pixels=0,
|
||||
val_limit=100,
|
||||
hue_default=0,
|
||||
sat_default=100,
|
||||
rgb_order=(1, 0, 2), # GRB WS2812
|
||||
val_default=100,
|
||||
hue_step=5,
|
||||
sat_step=5,
|
||||
val_step=5,
|
||||
animation_speed=1,
|
||||
breathe_center=1, # 1.0-2.7
|
||||
knight_effect_length=3,
|
||||
animation_mode=AnimationModes.STATIC,
|
||||
reverse_animation=False,
|
||||
)
|
||||
```
|
||||
|
||||
## Hardware Modification
|
||||
|
||||
To add RGB LED's to boards that don't support them directly, you will have to add a 3 wires. The power wire will run on 3.3v or 5v (depending on the LED),
|
||||
ground, and data pins will need added to an unused pin on your microcontroller unless your keyboard has specific solder points for them. With those 3 wires
|
||||
connected, set the pixel_pin as described above, and you are ready to use your RGB LED's/Neopixels.
|
||||
|
||||
## ADVANCED USAGE
|
||||
If you wish to interact with these as you would normal LED's and do not want help from KMK, you can disable all helper functions from working and access the
|
||||
neopixel object directly like this.
|
||||
```python
|
||||
keyboard.pixels.disable_auto_write = True
|
||||
keyboard.pixels.neopixel() # <-- This is the neopixel object
|
||||
```
|
||||
|
||||
## User animations
|
||||
User animations can be created as well. An example of a light show would look like this
|
||||
```python
|
||||
from kmk.keys import make_key
|
||||
|
||||
def start_light_show(*args, **kwargs):
|
||||
# Setting mode to user will use the user animation
|
||||
keyboard.pixels.animation_mode = 'user'
|
||||
|
||||
|
||||
def light_show(self):
|
||||
# This is the code that is run every cycle that can serve as an animation
|
||||
# Refer to the kmk/rgb.py for actual examples of what has been done
|
||||
self.hue = (self.hue + 35) % 360
|
||||
keyboard.pixels.set_hsv_fill(self.hue, self.sat, self.val)
|
||||
return self
|
||||
|
||||
|
||||
# This is what "gives" your function to KMK so it knows what your animation code is
|
||||
keyboard.rgb_config['user_animation'] = light_show
|
||||
|
||||
# Makes a key that would start your animation
|
||||
LS = make_key(on_press=start_light_show)
|
||||
|
||||
keymap = [...LS,...]
|
||||
```
|
||||
To add RGB LED's to boards that don't support them directly, you will have to
|
||||
add a 3 wires. The power wire will run on 3.3v or 5v (depending on the LED),
|
||||
ground, and data pins will need added to an unused pin on your microcontroller
|
||||
unless your keyboard has specific solder points for them. With those 3 wires
|
||||
connected, set the `pixel_pin` as described above, and you are ready to use your
|
||||
RGB LED's/Neopixels.
|
||||
|
||||
## Troubleshooting
|
||||
### Incorrect colors
|
||||
If your colors are incorrect, check the pixel order of your specific LED's. Here are some common ones.
|
||||
* WS2811, WS2812, WS2812B, WS2812C are all GRB (1, 0, 2)
|
||||
* SK6812, SK6812MINI, SK6805 are all GRB (1, 0, 2)
|
||||
* Neopixels will vary depending on which one you buy. It will be listed on the product page.# Troubleshooting
|
||||
|
||||
* Neopixels will vary depending on which one you buy. It will be listed on the product page.
|
||||
|
||||
### Lights don't turn on
|
||||
Make sure that your board supports LED backlight by checking for a line with "PIXEL_PIN". If it does not, you can add it to your keymap.
|
||||
If you added the LED's yourself, you will also need to set num_pixels to the number of installed LED's in total.
|
||||
|
||||
Make sure that your board supports LED backlight by checking for a line with
|
||||
`PIXEL_PIN`. If it does not, you can add it to your keymap. If you added the
|
||||
LED's yourself, you will also need to set `num_pixels` to the number of
|
||||
installed LED's in total.
|
||||
|
Reference in New Issue
Block a user