Compare commits

...

30 commits

Author SHA1 Message Date
09b2833a4b Tippfehler 2021-10-24 17:08:14 +02:00
66b40e10e3 neues layout wo seite weiß ist und fläche in layer farbe 2021-08-27 11:42:01 +02:00
03bf66054d nicht gentuzt Tasten weiß 2021-08-25 23:31:22 +02:00
9851f2290e Farben nutzbar passend zu auswahl 2021-08-25 23:21:11 +02:00
bacb410f1f weiß als Farbe 2021-08-25 23:05:38 +02:00
f9ef3df8c9 Kommentare & Farben 2021-08-25 22:45:55 +02:00
edef2aedb1 debounce 2021-08-25 22:32:18 +02:00
da7488af4e eigene keymap hinzugefügt 2021-08-25 22:18:23 +02:00
ffa4e73c6d Farbe layer 3 entfernt 2021-08-25 20:50:25 +02:00
9defb76dad Startanimation 2021-08-25 13:25:57 +02:00
ad053d624b Kommentare 2021-08-25 11:56:14 +02:00
a385b59507 Layer 3 Farben + Tasten umbelegt 2021-08-25 11:19:05 +02:00
20ffff4db4 Beispiel Strings 2021-08-25 10:56:37 +02:00
44fa22b0ca Layer 1 . statt , 2021-08-25 10:49:51 +02:00
16557ba128 Layer 0&2 leergemacht; derzeit ungenutzt 2021-08-25 10:48:08 +02:00
abeb3fdf1c Layer in "send" eingebaut 2021-08-25 10:44:33 +02:00
52c686a0e7 Kommentare 2021-08-25 10:44:12 +02:00
92d0bab96c debounce = short_debounce 2021-08-25 10:43:56 +02:00
4a0c85f04a Farben angepast 2021-08-25 10:35:52 +02:00
8b180675a8 Layer 3 umsortiert 2021-08-25 10:28:30 +02:00
8489556ebc Layer 0 hinzugfügt 2021-08-25 10:22:31 +02:00
01b1e0579a Bug: flackernde LEDs//flickering LEDs
---
sind an und aus gegangen
2021-08-25 10:13:23 +02:00
93c1d571af Color-Feedback Layer-Key ausgestellt 2021-08-25 10:11:42 +02:00
cb1c850fb6 Start Layer auf 3 gestellt 2021-08-25 10:11:01 +02:00
973a79c803 Layer 2 hinzugefügt 2021-08-25 10:10:49 +02:00
5ef9402099 Belegung Numpad-Layer angepasst 2021-08-25 10:10:23 +02:00
271fe80a71 header entfernt 2021-08-25 10:10:08 +02:00
4d90e5d019 layer2 ausgebaut 2021-08-25 09:48:08 +02:00
5dd89d820e code + url + keymap hinzugefügt 2021-08-25 09:45:46 +02:00
Philip Howard
831f31e862
Merge pull request #6 from pimoroni/patch-obs-example
OBS studio Toggle and Mutex example
2021-05-19 11:15:24 +01:00
5 changed files with 418 additions and 0 deletions

150
code/code.py Normal file
View file

@ -0,0 +1,150 @@
import board
import time
from keybow2040 import Keybow2040
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode
# Set up Keybow
i2c = board.I2C()
keybow = Keybow2040(i2c)
keys = keybow.keys
# Set up the keyboard and layout
keyboard = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(keyboard)
# Set up consumer control (used to send media key presses)
consumer_control = ConsumerControl(usb_hid.devices)
# Our layers. The key of item in the layer dictionary is the key number on
# Keybow to map to, and the value is the key press to send.
# Note that keys 0-3 are reserved as the modifier and layer selector keys
# respectively.
layer_0 = {}
layer_1 = {4: Keycode.PERIOD,
5: Keycode.ONE,
6: Keycode.FOUR,
7: Keycode.SEVEN,
8: Keycode.ZERO,
9: Keycode.TWO,
10: Keycode.FIVE,
11: Keycode.EIGHT,
12: Keycode.ENTER,
13: Keycode.THREE,
14: Keycode.SIX,
15: Keycode.NINE}
layer_2 = {4: "Mit freundlichen Gruessen\nMichael Grote "
}
layer_3 = {6: ConsumerControlCode.VOLUME_DECREMENT,
7: ConsumerControlCode.SCAN_PREVIOUS_TRACK,
10: ConsumerControlCode.MUTE,
11: ConsumerControlCode.PLAY_PAUSE,
14: ConsumerControlCode.VOLUME_INCREMENT,
15: ConsumerControlCode.SCAN_NEXT_TRACK}
layers = {0: layer_0,
1: layer_1,
2: layer_2,
3: layer_3}
selectors = {0: keys[0],
1: keys[1],
2: keys[2],
3: keys[3]}
# Start on layer X
current_layer = 1
# The colours for each layer
# https://gist.github.com/ninrod/b0f86d77ebadaccf7d9d4431dd8e2983
# https://colorhunt.co/palette/f7fd04f9b208f98404fc5404
colours = {0: (247, 253, 4),
1: (249, 178, 8),
2: (249, 132, 4),
3: (252, 84, 4)}
layer_keys = range(4, 16)
# Set the LEDs for each key in the current layer
for k in layers[current_layer].keys():
keys[k].set_led(*colours[current_layer])
# To prevent the strings (as opposed to single key presses) that are sent from
# refiring on a single key press, the debounce time for the strings has to be
# longer.
short_debounce = 0.03
long_debounce = 0.15
debounce = short_debounce
fired = False
# startanimation - 8bit
keybow.set_all(0,0,255)
keybow.set_all(0,255,0)
keybow.set_all(0,255,255)
keybow.set_all(255,0,0)
keybow.set_all(255,0,255)
keybow.set_all(255,255,0)
keybow.set_all(255,255,255)
keybow.set_all(0,0,0)
while True:
# Always remember to call keybow.update()!
keybow.update()
for layer in layers.keys():
keys[layer].set_led(*colours[layer])
if current_layer != layer:
if selectors[layer].pressed:
current_layer = layer
# Set the key LEDs first to off, then to their layer colour
# sonst bleiben ungelegte keys in der alten farbe
for k in layer_keys:
keys[k].set_led(0, 0, 0)
for k in layers[layer].keys():
# setze überall farben
keys[k].set_led(*colours[layer])
# setze zusätzlich farben in layer3
#if current_layer == 3:
# keys[10].set_led(255,255,0) # rot
# keys[11].set_led(30,144,255) #blau
# Loop through all of the keys in the layer and if they're pressed, get the
# key code from the layer's key map
for k in layers[current_layer].keys():
if keys[k].pressed:
key_press = layers[current_layer][k]
# If the key hasn't just fired (prevents refiring)
if not fired:
fired = True
# Send the right sort of key press and set debounce for each
if current_layer == 0:
keyboard.send(key_press)
elif current_layer == 1:
keyboard.send(key_press)
# sendet strings
# deswegen längerer debounce
elif current_layer == 2:
debounce = long_debounce
layout.write(key_press)
# sendet hid_keycodes.. mute usw.
elif current_layer == 3:
consumer_control.send(key_press)
# If enough time has passed, reset the fired variable
if fired and time.monotonic() - keybow.time_of_last_press > debounce:
fired = False

124
code/code_eigenbau.py Normal file
View file

@ -0,0 +1,124 @@
import board
import time
from keybow2040 import Keybow2040
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode
# Set up Keybow
i2c = board.I2C()
keybow = Keybow2040(i2c)
keys = keybow.keys
# Set up the keyboard and layout
keyboard = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(keyboard)
# Set up consumer control (used to send media key presses)
consumer_control = ConsumerControl(usb_hid.devices)
# Denfiniere Layer als Dictionary
layer_0 = {}
layer_1 = {4: Keycode.PERIOD,
5: Keycode.ONE,
6: Keycode.FOUR,
7: Keycode.SEVEN,
8: Keycode.ZERO,
9: Keycode.TWO,
10: Keycode.FIVE,
11: Keycode.EIGHT,
12: Keycode.ENTER,
13: Keycode.THREE,
14: Keycode.SIX,
15: Keycode.NINE}
layer_2 = {4: "Mit freundlichen Gruessen\nMichael Grote"
}
layer_3 = {6: ConsumerControlCode.VOLUME_DECREMENT,
7: ConsumerControlCode.SCAN_PREVIOUS_TRACK,
10: ConsumerControlCode.MUTE,
11: ConsumerControlCode.PLAY_PAUSE,
14: ConsumerControlCode.VOLUME_INCREMENT,
15: ConsumerControlCode.SCAN_NEXT_TRACK}
layers = {0: layer_0,
1: layer_1,
2: layer_2,
3: layer_3}
# welches ist der aktive Layer
current_layer = 1
# welche Tasten dienen nicht der Layer-Auswahl
nutzbare_tasten = range(4,16) #zählt von 1-16; nicht 0-15
# Debounce-Werte
short_debounce = 0.03
long_debounce = 0.15
debounce = short_debounce
taste_ausgelöst = False
# Farben der Layer als Dictionary
# https://gist.github.com/ninrod/b0f86d77ebadaccf7d9d4431dd8e2983
# https://colorhunt.co/palette/f7fd04f9b208f98404fc5404
colours = {0: (247, 253, 4),
1: (249, 178, 8),
2: (249, 132, 4),
3: (252, 84, 4),
4: (255,155,255)} # weiß
# setze farben auf layer keys und den nutzbaren tasten nach dem start
keybow.keys[0].set_led(*colours[0])
keybow.keys[1].set_led(*colours[1])
keybow.keys[2].set_led(*colours[2])
keybow.keys[3].set_led(*colours[3])
while True:
# Always remember to call keybow.update()!
keybow.update()
# wenn layer-auswahl key gedrückt dann..
if keys[0].pressed:
# setze ALLE nutzbaren tasten auf weiß
for k in nutzbare_tasten:
keys[k].set_led(*colours[4])
# setze current layer
current_layer = 0
elif keys[1].pressed:
for k in nutzbare_tasten:
keys[k].set_led(*colours[4])
current_layer = 1
elif keys[2].pressed:
for k in nutzbare_tasten:
keys[k].set_led(*colours[4])
current_layer = 2
elif keys[3].pressed:
for k in nutzbare_tasten:
keys[k].set_led(*colours[4])
current_layer = 3
# färbe zum layer gehörende tasten ein
for b in layers[current_layer].keys():
keys[b].set_led(*colours[current_layer])
# "frage" alle tasten ab
for taste in layers[current_layer].keys():
# wenn gedrückt
if keys[taste].pressed:
# setze keycode
key_press = layers[current_layer][taste]
# prufe ob taste vor kurzem ausgelöst wurde
if not taste_ausgelöst:
taste_ausgelöst = True
# prüfe layer wegen debounce und "sende"-art
if current_layer == 0:
keyboard.send(key_press)
elif current_layer == 1:
keyboard.send(key_press)
elif current_layer == 2:
debounce = long_debounce
layout.write(key_press)
elif current_layer == 3:
consumer_control.send(key_press)
# hebe "debounce" auf
if taste_ausgelöst and time.monotonic() - keybow.time_of_last_press > debounce:
taste_ausgelöst = False

View file

@ -0,0 +1,137 @@
import board
import time
from keybow2040 import Keybow2040
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from adafruit_hid.consumer_control import ConsumerControl
from adafruit_hid.consumer_control_code import ConsumerControlCode
# Set up Keybow
i2c = board.I2C()
keybow = Keybow2040(i2c)
keys = keybow.keys
# Set up the keyboard and layout
keyboard = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(keyboard)
# Set up consumer control (used to send media key presses)
consumer_control = ConsumerControl(usb_hid.devices)
# Denfiniere Layer als Dictionary
layer_0 = {}
layer_1 = {4: Keycode.PERIOD,
5: Keycode.ONE,
6: Keycode.FOUR,
7: Keycode.SEVEN,
8: Keycode.ZERO,
9: Keycode.TWO,
10: Keycode.FIVE,
11: Keycode.EIGHT,
12: Keycode.ENTER,
13: Keycode.THREE,
14: Keycode.SIX,
15: Keycode.NINE}
layer_2 = {4: "Mit freundlichen Gruessen\nMichael Grote "
}
layer_3 = {6: ConsumerControlCode.VOLUME_DECREMENT,
7: ConsumerControlCode.SCAN_PREVIOUS_TRACK,
10: ConsumerControlCode.MUTE,
11: ConsumerControlCode.PLAY_PAUSE,
14: ConsumerControlCode.VOLUME_INCREMENT,
15: ConsumerControlCode.SCAN_NEXT_TRACK}
layers = {0: layer_0,
1: layer_1,
2: layer_2,
3: layer_3}
# welches ist der aktive Layer
current_layer = 1
# weclche Tasten dienen nicht der Layer-Auswahl
nutzbare_tasten = range(4,16) #zählt von 1-16; nicht 0-15
# Debounce-Werte
short_debounce = 0.03
long_debounce = 0.15
debounce = short_debounce
taste_ausgelöst = False
# Farben der Layer als Dictionary
# https://gist.github.com/ninrod/b0f86d77ebadaccf7d9d4431dd8e2983
# https://colorhunt.co/palette/f7fd04f9b208f98404fc5404
colours = {0: (247, 253, 4),
1: (249, 178, 8),
2: (249, 132, 4),
3: (252, 84, 4),
4: (255,155,255)} # weiß
# setze farben auf layer keys und den nutzbaren tasten nach dem start
keybow.keys[0].set_led(*colours[0])
keybow.keys[1].set_led(*colours[1])
keybow.keys[2].set_led(*colours[2])
keybow.keys[3].set_led(*colours[3])
while True:
# Always remember to call keybow.update()!
keybow.update()
# wenn layer-auswahl key gedrückt dann..
if keys[0].pressed:
# setze ALLE nutzbaren tasten auf weiß
for k in nutzbare_tasten:
keys[k].set_led(*colours[0])
keybow.keys[0].set_led(*colours[0])
keybow.keys[1].set_led(*colours[4])
keybow.keys[2].set_led(*colours[4])
keybow.keys[3].set_led(*colours[4])
# setze current layer
current_layer = 0
elif keys[1].pressed:
for k in nutzbare_tasten:
keys[k].set_led(*colours[1])
keybow.keys[0].set_led(*colours[4])
keybow.keys[1].set_led(*colours[1])
keybow.keys[2].set_led(*colours[4])
keybow.keys[3].set_led(*colours[4])
current_layer = 1
elif keys[2].pressed:
for k in nutzbare_tasten:
keys[k].set_led(*colours[2])
keybow.keys[0].set_led(*colours[4])
keybow.keys[1].set_led(*colours[4])
keybow.keys[2].set_led(*colours[2])
keybow.keys[3].set_led(*colours[4])
current_layer = 2
elif keys[3].pressed:
for k in nutzbare_tasten:
keys[k].set_led(*colours[3])
keybow.keys[0].set_led(*colours[4])
keybow.keys[1].set_led(*colours[4])
keybow.keys[2].set_led(*colours[4])
keybow.keys[3].set_led(*colours[3])
current_layer = 3
# "frage" alle tasten ab
for taste in layers[current_layer].keys():
# wenn gedrückt
if keys[taste].pressed:
# setze keycode
key_press = layers[current_layer][taste]
# prufe ob taste vor kurzem ausgelöst wurde
if not taste_ausgelöst:
taste_ausgelöst = True
# prüfe layer wegen debounce und "sende"-art
if current_layer == 0:
keyboard.send(key_press)
elif current_layer == 1:
keyboard.send(key_press)
elif current_layer == 2:
debounce = long_debounce
layout.write(key_press)
elif current_layer == 3:
consumer_control.send(key_press)
# hebe "debounce" auf
if taste_ausgelöst and time.monotonic() - keybow.time_of_last_press > debounce:
taste_ausgelöst = False

5
keymap.md Normal file
View file

@ -0,0 +1,5 @@
USB
3 7 11 15
2 6 10 14
1 5 9 13
0 4 8 12

2
urls.txt Normal file
View file

@ -0,0 +1,2 @@
https://github.com/pimoroni/keybow2040-circuitpython
https://learn.pimoroni.com/tutorial/hel/assembling-keybow-2040