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 time
|
||||||
import board
|
import board
|
||||||
import digitalio
|
import digitalio
|
||||||
|
import rotaryio
|
||||||
import usb_hid
|
import usb_hid
|
||||||
|
|
||||||
# Regular keys
|
# Regular keys
|
||||||
|
@ -26,12 +27,16 @@ from adafruit_hid.keyboard import Keyboard
|
||||||
from keyboard_layout_win_fr import KeyboardLayout
|
from keyboard_layout_win_fr import KeyboardLayout
|
||||||
from keycode_win_fr import Keycode
|
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.
|
# When in ALT mode, buttons use an alternative keycode.
|
||||||
ALT = False
|
ALT = False
|
||||||
|
|
||||||
# KB setup
|
# KB setup
|
||||||
keyboard = Keyboard(usb_hid.devices)
|
keyboard = Keyboard(usb_hid.devices)
|
||||||
keyboard_layout = KeyboardLayout(keyboard)
|
keyboard_layout = KeyboardLayout(keyboard)
|
||||||
|
|
||||||
# Buttons setup
|
# Buttons setup
|
||||||
buttons_gpio = {
|
buttons_gpio = {
|
||||||
|
@ -88,4 +93,10 @@ while True:
|
||||||
if buttons_gpio[btn]['switch_setup']['DIO'].value:
|
if buttons_gpio[btn]['switch_setup']['DIO'].value:
|
||||||
buttons_gpio[btn]['switch_setup']['DIO'].value = False
|
buttons_gpio[btn]['switch_setup']['DIO'].value = False
|
||||||
ALT = 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)
|
time.sleep(btn_scan_delay)
|
||||||
|
|
Loading…
Reference in New Issue