Add rotary encoder support

This commit is contained in:
ABelliqueux 2025-01-11 14:49:15 +01:00
parent eabb6e908a
commit 42b97aeea7
1 changed files with 12 additions and 1 deletions

13
code.py
View File

@ -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)