To use this you need to make some changes to your kb.py as well as you main.py I will break it into two sections for you.
- Display images
- Display text
- Set images or text to react to your layer
- React to battery percentage
- React to WPM
You need these frozen into your CircuitPython or in a lib folder at the root of your drive.
- Adafruit_CircuitPython_DisplayIO_SSD1306
- Adafruit_CircuitPython_Display_Text
- Download .mpy versions from Adafruit_CircuitPython_Bundle
Your chosen board may already have these changes done If not you will need to add them.
You need to add 'SCL' and SDA to your keyboard. The pins the OLED are connected to on your controller may not be called "SCL"and "SDA" they could be "GP21" and "GP13" for example. The best way to find out what they are is look at the boards pinout.
Make this change to your kb.py
file:
SCL=board.SCL
SDA=board.SDA
These are the changes that need to be made / added to your main.py
No matter how you are going to use the OLED you need this part (in main.py
):
from kmk.extensions.peg_oled_Display import Oled,OledDisplayMode,OledReactionType,OledData
keyboard = KMKKeyboard()
# ... Other oled code
keyboard.extensions.append(oled)
So the config for photos is quite simple. Getting the photos maybe not so much. I will explain.
Oled
takes 2-3 arguments
OledData
OledData
can take image or corner_one, corner_two, corner_three and corner_four- Every item in
OledData
has 2 fields - 0: This is the reaction type right now it can be
OledReactionType.LAYER
orOledReactionType.STATIC
- 1: An array of the items you want to show for the reaction. In this example 4 images to switch on the 4 layers
- To display called as
toDisplay=OledDisplayMode.TXT
this takes aOledDisplayMode
TXT or IMG.- This tells the extension to load images or text.
- Flip called as "flip= Boolean" this will simply flip your display.
oled = Oled(OledData(image={0:OledReactionType.LAYER,1:["1.bmp","2.bmp","1.bmp","2.bmp"]}),toDisplay=OledDisplayMode.IMG,flip=False)
In this code example we are saying to react to the layer change and load a image filed named "1.bmp" for layer one and "2.bmp" for layer two and so on.
So you need to include all the images in your CircuitPython drive in the root along side main.py
Your images need to be 128x32 pixels and should only be black and white. After you have made your image you can save as a "monochrome bmp" this will save you a lot of space.
OK now we get into something that looks a lot more complicated but we will get though it.
Almost everything is the same We swap toDisplay
to TXT and there are more items in the OledData
Class, lets get into that.
- Top left
- Top right
- Bottom left
- Bottom right
After that is the same as the previous example. Each one has two fields 0:the reaction type. 1:what to display
In this code we will always display the word "layer" in the top left corner of the screen then the other 3 corners will swap depending on the layer.
oled = Oled(
OledData(
corner_one={0:OledReactionType.STATIC,1:["layer"]},
corner_two={0:OledReactionType.LAYER,1:["1","2","3","4"]},
corner_three={0:OledReactionType.LAYER,1:["base","raise","lower","adjust"]},
corner_four={0:OledReactionType.LAYER,1:["qwerty","nums","shifted","leds"]}
),
toDisplay=OledDisplayMode.TXT,flip=False)
Your OLED data can be a variable as shown below with images.
oled_display_data=OledData(image={0:OledReactionType.LAYER,1:["1.bmp","2.bmp","1.bmp","2.bmp"]})
oled = Oled(oled_display_data,toDisplay=OledDisplayMode.IMG,flip=False)