This commit is contained in:
ABelliqueux 2024-09-27 16:28:32 +02:00
parent 7fe4c04a6a
commit ce064b5912
2 changed files with 49 additions and 34 deletions

64
code.py
View File

@ -4,12 +4,13 @@
# Using Adafruit USB_HID Library : https://github.com/adafruit/Adafruit_CircuitPython_HID/releases # Using Adafruit USB_HID Library : https://github.com/adafruit/Adafruit_CircuitPython_HID/releases
# #
# Buttons default mapping # Buttons default mapping
# Red = F # Red = Del/E
# Green = G # Green = Spacebar/Return
# Blue = H # Blue = Right arrow/Up
# Black = I # Yellow = Left arrow/Down
# Black = Esc/R
# #
# Yellow on : multimedia mode # Switch on : Alt mode
# #
# Forked from # Forked from
# DroneBot Workshop 2021 # DroneBot Workshop 2021
@ -20,30 +21,27 @@ import board
import digitalio import digitalio
import usb_hid import usb_hid
# Regulare keys # Regular keys
from adafruit_hid.keyboard import Keyboard 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
# multimedia keys # When in ALT mode, buttons use an alternative keycode.
# ~ from adafruit_hid.consumer_control import ConsumerControl ALT = False
# ~ from adafruit_hid.consumer_control_code import ConsumerControlCode
# ~ cc = ConsumerControl(usb_hid.devices)
# 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
# Change GPIOs according to HW
buttons_gpio = { buttons_gpio = {
# name GPIO Keycode State DigitalIO (switch) # name GPIO Keycode_1 Keycode_2(ALT mode) State DigitalIO (switch)
"red" : dict(gpio=board.GP18, keycode=Keycode.D, state=False, DIO=None), "red" : dict(gpio=board.GP18, keycode_1=Keycode.DELETE, keycode_2=Keycode.E, state=False, DIO=None),
"green" : dict(gpio=board.GP19, keycode=Keycode.N, 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=Keycode.J, state=False, DIO=None), "blue" : dict(gpio=board.GP16, keycode_1=Keycode.RIGHT_ARROW, keycode_2=Keycode.DOWN_ARROW, state=False, DIO=None),
"black" : dict(gpio=board.GP20, keycode=Keycode.E, state=False, DIO=None), "black" : dict(gpio=board.GP20, keycode_1=Keycode.ESCAPE, keycode_2=Keycode.R, state=False, DIO=None),
"yellow": dict(gpio=board.GP17, keycode=Keycode.B, state=False, DIO=None), "yellow": dict(gpio=board.GP17, keycode_1=Keycode.LEFT_ARROW,keycode_2=Keycode.UP_ARROW,state=False, DIO=None),
"switch": dict(gpio=board.GP21, keycode=Keycode.LEFT_SHIFT, state=False, DIO=None, switch_setup=dict(gpio=board.GP7, 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))
} }
# GPIO setup # GPIO setup
@ -60,14 +58,32 @@ btn_scan_delay = 1/200
while True: while True:
for btn in buttons_gpio: for btn in buttons_gpio:
# If digital input is high and was not pressed previously
if buttons_gpio[btn]['DIO'].value and not buttons_gpio[btn]['state']: if buttons_gpio[btn]['DIO'].value and not buttons_gpio[btn]['state']:
keyboard.press(buttons_gpio[btn]['keycode']) if ALT:
buttons_gpio[btn]['state'] = not buttons_gpio[btn]['state'] if buttons_gpio[btn]['keycode_2'] is not None:
keyboard.press(buttons_gpio[btn]['keycode_2'])
else:
if buttons_gpio[btn]['keycode_1'] is not None:
keyboard.press(buttons_gpio[btn]['keycode_1'])
buttons_gpio[btn]['state'] = True
# Turn light on, turn ALT mode on
if 'switch_setup' in buttons_gpio[btn]: if 'switch_setup' in buttons_gpio[btn]:
buttons_gpio[btn]['switch_setup']['DIO'].value = True if not buttons_gpio[btn]['switch_setup']['DIO'].value:
buttons_gpio[btn]['switch_setup']['DIO'].value = True
ALT = True
# If digital input is down and was pressed previously
if not buttons_gpio[btn]['DIO'].value and buttons_gpio[btn]['state']: if not buttons_gpio[btn]['DIO'].value and buttons_gpio[btn]['state']:
keyboard.release(buttons_gpio[btn]['keycode']) if ALT:
buttons_gpio[btn]['state'] = not buttons_gpio[btn]['state'] if buttons_gpio[btn]['keycode_2'] is not None:
keyboard.release(buttons_gpio[btn]['keycode_2'])
else:
if buttons_gpio[btn]['keycode_1'] is not None:
keyboard.release(buttons_gpio[btn]['keycode_1'])
buttons_gpio[btn]['state'] = False
# Turn light off, turn ALT mode off
if 'switch_setup' in buttons_gpio[btn]: if 'switch_setup' in buttons_gpio[btn]:
buttons_gpio[btn]['switch_setup']['DIO'].value = False if buttons_gpio[btn]['switch_setup']['DIO'].value:
buttons_gpio[btn]['switch_setup']['DIO'].value = False
ALT = False
time.sleep(btn_scan_delay) time.sleep(btn_scan_delay)

View File

@ -3,19 +3,18 @@
![Outside](./picote-outside.jpg) ![Outside](./picote-outside.jpg)
![Inside](./picote-inside.jpg) ![Inside](./picote-inside.jpg)
Use a rpi pico and push buttons to send key strokes to a computer. Utiliser un [raspberry pi pico](https://www.raspberrypi.com/products/raspberry-pi-pico/) et des bouttons d'arcade pour simuler des touches de clavier.
This is the companion project to the [Stopi](/arthus/stopi) stop-motion software. Ce projet est le compagnon de [Stopi2](/arthus/stopi2).
## Software setup ## Installation
1. Upload 'code.py' and the 'lib' folder to the rpi pico Copier le fichier 'code.py' et le répertoire 'lib' à la base du pico.
2. Done
## Hadware setup ## Matériel nécessaire
* 5 push buttons * 5 bouttons poussoirs
* 1 ON/OFF switch with indicator light or a separate LED * 1 switch ON/OFF avec une LED intégrée ou en supplément.
* 1 330Ω resistor * 1 rsistance 330Ω
![The crude diagram](./picote-s.jpg) ![The crude diagram](./picote-s.jpg)