Add ALT key for rotary encoder
This commit is contained in:
parent
42b97aeea7
commit
88fb7d18db
25
code.py
25
code.py
|
@ -40,22 +40,22 @@ keyboard_layout = KeyboardLayout(keyboard)
|
|||
|
||||
# Buttons setup
|
||||
buttons_gpio = {
|
||||
# name GPIO Keycode_1 Keycode_2(ALT mode) State DigitalIO (switch)
|
||||
"red" : dict(gpio=board.GP18, keycode_1=Keycode.DELETE, keycode_2=Keycode.E, state=False, DIO=None),
|
||||
"green" : dict(gpio=board.GP19, keycode_1=Keycode.SPACEBAR, keycode_2=Keycode.RETURN, state=False, DIO=None),
|
||||
"blue" : dict(gpio=board.GP16, keycode_1=Keycode.RIGHT_ARROW, keycode_2=Keycode.UP_ARROW, state=False, DIO=None),
|
||||
"black" : dict(gpio=board.GP20, keycode_1=Keycode.O, keycode_2=Keycode.R, state=False, DIO=None),
|
||||
"yellow": dict(gpio=board.GP17, keycode_1=Keycode.LEFT_ARROW, keycode_2=Keycode.DOWN_ARROW,state=False, DIO=None),
|
||||
"switch": dict(gpio=board.GP21, keycode_1=None, keycode_2=None, state=False, DIO=None, switch_setup=dict(gpio=board.GP7, state=False, DIO=None)),
|
||||
"fn_1": dict(gpio=board.GP15, keycode_1=Keycode.W, keycode_2=Keycode.X, state=False, DIO=None),
|
||||
"fn_2": dict(gpio=board.GP14, keycode_1=Keycode.L, keycode_2=Keycode.F, state=False, DIO=None),
|
||||
# name GPIO Keycode_1 Keycode_2(ALT mode) State DigitalIO Pull (Switch)
|
||||
"red" : dict(gpio=board.GP18, keycode_1=Keycode.DELETE, keycode_2=Keycode.E, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
||||
"green" : dict(gpio=board.GP19, keycode_1=Keycode.SPACEBAR, keycode_2=Keycode.RETURN, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
||||
"blue" : dict(gpio=board.GP16, keycode_1=Keycode.RIGHT_ARROW, keycode_2=Keycode.UP_ARROW, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
||||
"black" : dict(gpio=board.GP20, keycode_1=Keycode.O, keycode_2=Keycode.R, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
||||
"yellow": dict(gpio=board.GP17, keycode_1=Keycode.LEFT_ARROW, keycode_2=Keycode.DOWN_ARROW,state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
||||
"switch": dict(gpio=board.GP21, keycode_1=None, keycode_2=None, state=False, DIO=None, pullr=digitalio.Pull.DOWN, switch_setup=dict(gpio=board.GP7, state=False, DIO=None)),
|
||||
"fn_1": dict(gpio=board.GP15, keycode_1=Keycode.W, keycode_2=Keycode.X, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
||||
"fn_2": dict(gpio=board.GP14, keycode_1=Keycode.L, keycode_2=Keycode.F, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
||||
}
|
||||
|
||||
# GPIO setup
|
||||
for btn in buttons_gpio:
|
||||
buttons_gpio[btn]['DIO'] = digitalio.DigitalInOut(buttons_gpio[btn]['gpio'])
|
||||
buttons_gpio[btn]['DIO'].direction = digitalio.Direction.INPUT
|
||||
buttons_gpio[btn]['DIO'].pull = digitalio.Pull.DOWN
|
||||
buttons_gpio[btn]['DIO'].pull = buttons_gpio[btn]['pullr']
|
||||
# Switch setup
|
||||
if 'switch_setup' in buttons_gpio[btn]:
|
||||
buttons_gpio[btn]['switch_setup']['DIO'] = digitalio.DigitalInOut(buttons_gpio[btn]['switch_setup']['gpio'])
|
||||
|
@ -95,7 +95,10 @@ while True:
|
|||
ALT = False
|
||||
pos = enc.position
|
||||
if pos > last_pos:
|
||||
keyboard.send(Keycode.A)
|
||||
if ALT:
|
||||
keyboard.send(Keycode.Q)
|
||||
else:
|
||||
keyboard.send(Keycode.A)
|
||||
elif pos < last_pos:
|
||||
keyboard.send(Keycode.Z)
|
||||
last_pos = pos
|
||||
|
|
Loading…
Reference in New Issue