debounce
This commit is contained in:
parent
da7488af4e
commit
edef2aedb1
1 changed files with 23 additions and 12 deletions
|
@ -60,6 +60,10 @@ layers = {0: layer_0,
|
||||||
|
|
||||||
current_layer = 1
|
current_layer = 1
|
||||||
nutzbare_tasten = range(4,16) #zählt von 1-16; nicht 0-15
|
nutzbare_tasten = range(4,16) #zählt von 1-16; nicht 0-15
|
||||||
|
short_debounce = 0.03
|
||||||
|
long_debounce = 0.15
|
||||||
|
debounce = short_debounce
|
||||||
|
taste_ausgelöst = False
|
||||||
|
|
||||||
# The colours for each layer
|
# The colours for each layer
|
||||||
# https://gist.github.com/ninrod/b0f86d77ebadaccf7d9d4431dd8e2983
|
# https://gist.github.com/ninrod/b0f86d77ebadaccf7d9d4431dd8e2983
|
||||||
|
@ -112,21 +116,28 @@ while True:
|
||||||
keybow.keys[3].set_led(252, 84, 4)
|
keybow.keys[3].set_led(252, 84, 4)
|
||||||
|
|
||||||
for taste in layers[current_layer].keys():
|
for taste in layers[current_layer].keys():
|
||||||
|
|
||||||
if keys[taste].pressed:
|
if keys[taste].pressed:
|
||||||
key_press = layers[current_layer][taste]
|
key_press = layers[current_layer][taste]
|
||||||
|
|
||||||
|
# If the key hasn't just fired (prevents refiring)
|
||||||
|
if not taste_ausgelöst:
|
||||||
|
taste_ausgelöst = True
|
||||||
|
|
||||||
|
# Send the right sort of key press and set debounce for each
|
||||||
if current_layer == 0:
|
if current_layer == 0:
|
||||||
keyboard.send(key_press)
|
keyboard.send(key_press)
|
||||||
elif current_layer == 1:
|
elif current_layer == 1:
|
||||||
keyboard.send(key_press)
|
keyboard.send(key_press)
|
||||||
elif current_layer == 2:
|
elif current_layer == 2:
|
||||||
|
debounce = long_debounce
|
||||||
layout.write(key_press)
|
layout.write(key_press)
|
||||||
elif current_layer == 3:
|
elif current_layer == 3:
|
||||||
consumer_control.send(key_press)
|
consumer_control.send(key_press)
|
||||||
|
|
||||||
|
|
||||||
# keycode = current_layer[key.number]
|
|
||||||
# if keys[taste].pressed:
|
|
||||||
# keyboard.send(keycode)
|
|
||||||
|
|
||||||
|
|
||||||
|
# If enough time has passed, reset the fired variable
|
||||||
|
if taste_ausgelöst and time.monotonic() - keybow.time_of_last_press > debounce:
|
||||||
|
taste_ausgelöst = False
|
||||||
# farben als vars
|
# farben als vars
|
||||||
|
|
Loading…
Reference in a new issue