Summary
macro keyboard for raspberry pi pico. uses 6 keys and one rotary encoder module. I don't have github so the code can be found below, uncommented and might need refactoring as this was a weekend project. The commands are hard coded and you should be able to infer the wiring from the code and the wiring images in the post printing tab. the final construction can be press fit or use 4 M2x19 bolts with captive nuts.
import board
import digitalio
import time
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import rotaryio
import board
keyboard=Keyboard(usb_hid.devices)
key1 = digitalio.DigitalInOut(board.GP2)
key1.switch_to_input(pull=digitalio.Pull.DOWN)
key2 = digitalio.DigitalInOut(board.GP3)
key2.switch_to_input(pull=digitalio.Pull.DOWN)
key3 = digitalio.DigitalInOut(board.GP4)
key3.switch_to_input(pull=digitalio.Pull.DOWN)
key4 = digitalio.DigitalInOut(board.GP5)
key4.switch_to_input(pull=digitalio.Pull.DOWN)
key5 = digitalio.DigitalInOut(board.GP6)
key5.switch_to_input(pull=digitalio.Pull.DOWN)
key6 = digitalio.DigitalInOut(board.GP7)
key6.switch_to_input(pull=digitalio.Pull.DOWN)
rotK = digitalio.DigitalInOut(board.GP22)
rotK.switch_to_input(pull=digitalio.Pull.UP)
clicked = True
pressed = False
encoder = rotaryio.IncrementalEncoder(board.GP26, board.GP27)
last_position = None
while True:
if not(not(key1.value) and not(key2.value) and not(key3.value) and not(key4.value) and not(key5.value) and not(key6.value)) and not(pressed):
if key1.value:
keyboard.press(Keycode.LEFT_SHIFT)
keyboard.press(Keycode.WINDOWS)
keyboard.press(Keycode.S)
keyboard.release(Keycode.S)
keyboard.release(Keycode.WINDOWS)
keyboard.release(Keycode.LEFT_SHIFT)
if key2.value:
keyboard.press(Keycode.WINDOWS)
time.sleep(0.1)
keyboard.press(Keycode.S)
time.sleep(0.1)
keyboard.release(Keycode.S)
time.sleep(0.1)
keyboard.release(Keycode.WINDOWS)
time.sleep(0.1)
keyboard.press(Keycode.P)
time.sleep(0.1)
keyboard.release(Keycode.P)
time.sleep(0.1)
keyboard.press(Keycode.O)
time.sleep(0.1)
keyboard.release(Keycode.O)
time.sleep(0.1)
keyboard.press(Keycode.W)
time.sleep(0.1)
keyboard.release(Keycode.W)
time.sleep(0.1)
keyboard.press(Keycode.ENTER)
time.sleep(0.1)
keyboard.release(Keycode.ENTER)
if key3.value:
keyboard.press(Keycode.WINDOWS)
time.sleep(0.1)
keyboard.press(Keycode.S)
time.sleep(0.1)
keyboard.release(Keycode.S)
time.sleep(0.1)
keyboard.release(Keycode.WINDOWS)
time.sleep(0.1)
keyboard.press(Keycode.T)
time.sleep(0.1)
keyboard.release(Keycode.T)
time.sleep(0.1)
keyboard.press(Keycode.I)
time.sleep(0.1)
keyboard.release(Keycode.I)
time.sleep(0.1)
keyboard.press(Keycode.N)
time.sleep(0.1)
keyboard.release(Keycode.N)
time.sleep(0.1)
keyboard.press(Keycode.ENTER)
time.sleep(0.1)
keyboard.release(Keycode.ENTER)
if key4.value:
keyboard.press(Keycode.WINDOWS)
time.sleep(0.1)
keyboard.press(Keycode.E)
time.sleep(0.1)
keyboard.release(Keycode.E)
time.sleep(0.1)
keyboard.release(Keycode.WINDOWS)
if key5.value:
keyboard.press(Keycode.WINDOWS)
time.sleep(0.1)
keyboard.press(Keycode.S)
time.sleep(0.1)
keyboard.release(Keycode.S)
time.sleep(0.1)
keyboard.release(Keycode.WINDOWS)
time.sleep(0.1)
keyboard.press(Keycode.C)
time.sleep(0.1)
keyboard.release(Keycode.C)
time.sleep(0.1)
keyboard.press(Keycode.U)
time.sleep(0.1)
keyboard.release(Keycode.U)
time.sleep(0.1)
keyboard.press(Keycode.R)
time.sleep(0.1)
keyboard.release(Keycode.R)
time.sleep(0.1)
keyboard.press(Keycode.ENTER)
time.sleep(0.1)
keyboard.release(Keycode.ENTER)
if key6.value:
keyboard.press(Keycode.WINDOWS)
time.sleep(0.1)
keyboard.press(Keycode.S)
time.sleep(0.1)
keyboard.release(Keycode.S)
time.sleep(0.1)
keyboard.release(Keycode.WINDOWS)
time.sleep(0.1)
keyboard.press(Keycode.T)
time.sleep(0.1)
keyboard.release(Keycode.T)
time.sleep(0.1)
keyboard.press(Keycode.H)
time.sleep(0.1)
keyboard.release(Keycode.H)
time.sleep(0.1)
keyboard.press(Keycode.O)
time.sleep(0.1)
keyboard.release(Keycode.O)
time.sleep(0.1)
keyboard.press(Keycode.ENTER)
time.sleep(0.1)
keyboard.release(Keycode.ENTER)
pressed = True
print("down")
if not(key1.value) and not(key2.value) and not(key3.value) and not(key4.value) and not(key5.value) and not(key6.value) and pressed:
pressed = False
print("up")
if not(rotK.value) and clicked:
clicked = False
keyboard.press(Keycode.LEFT_ALT)
print("down")
if rotK.value and not(clicked):
clicked = True
keyboard.release(Keycode.LEFT_ALT)
print("up")
position = encoder.position
if last_position is None or position != last_position:
if not(clicked):
if position > last_position:
keyboard.press(Keycode.TAB)
keyboard.release(Keycode.TAB)
if position < last_position:
keyboard.press(Keycode.LEFT_SHIFT)
keyboard.press(Keycode.TAB)
keyboard.release(Keycode.TAB)
keyboard.release(Keycode.LEFT_SHIFT)
if clicked and last_position != None:
if position > last_position:
keyboard.press(Keycode.TAB)
keyboard.release(Keycode.TAB)
if position < last_position:
keyboard.press(Keycode.LEFT_SHIFT)
keyboard.press(Keycode.TAB)
keyboard.release(Keycode.TAB)
keyboard.release(Keycode.LEFT_SHIFT)
last_position = position
Print Settings
Printer Brand:
Creality
Printer:
Ender 3
Rafts:
No
Supports:
No
Resolution:
200
Infill:
38
Post-Printing
32924836
32924837
32924838
32924840
Source du modèle
