Add rotary encoder support
This commit is contained in:
parent
eabb6e908a
commit
42b97aeea7
13
code.py
13
code.py
|
@ -19,6 +19,7 @@
|
|||
import time
|
||||
import board
|
||||
import digitalio
|
||||
import rotaryio
|
||||
import usb_hid
|
||||
|
||||
# Regular keys
|
||||
|
@ -26,12 +27,16 @@ from adafruit_hid.keyboard import Keyboard
|
|||
from keyboard_layout_win_fr import KeyboardLayout
|
||||
from keycode_win_fr import Keycode
|
||||
|
||||
# Rotary encoder setup
|
||||
enc = rotaryio.IncrementalEncoder(board.GP0, board.GP1)
|
||||
last_pos = 0
|
||||
|
||||
# When in ALT mode, buttons use an alternative keycode.
|
||||
ALT = False
|
||||
|
||||
# KB setup
|
||||
keyboard = Keyboard(usb_hid.devices)
|
||||
keyboard_layout = KeyboardLayout(keyboard)
|
||||
keyboard_layout = KeyboardLayout(keyboard)
|
||||
|
||||
# Buttons setup
|
||||
buttons_gpio = {
|
||||
|
@ -88,4 +93,10 @@ while True:
|
|||
if buttons_gpio[btn]['switch_setup']['DIO'].value:
|
||||
buttons_gpio[btn]['switch_setup']['DIO'].value = False
|
||||
ALT = False
|
||||
pos = enc.position
|
||||
if pos > last_pos:
|
||||
keyboard.send(Keycode.A)
|
||||
elif pos < last_pos:
|
||||
keyboard.send(Keycode.Z)
|
||||
last_pos = pos
|
||||
time.sleep(btn_scan_delay)
|
||||
|
|
Loading…
Reference in New Issue