diff --git a/code.py b/code.py index cc24f28..162942c 100644 --- a/code.py +++ b/code.py @@ -4,12 +4,13 @@ # Using Adafruit USB_HID Library : https://github.com/adafruit/Adafruit_CircuitPython_HID/releases # # Buttons default mapping -# Red = F -# Green = G -# Blue = H -# Black = I +# Red = Del/E +# Green = Spacebar/Return +# Blue = Right arrow/Up +# Yellow = Left arrow/Down +# Black = Esc/R # -# Yellow on : multimedia mode +# Switch on : Alt mode # # Forked from # DroneBot Workshop 2021 @@ -20,30 +21,27 @@ import board import digitalio import usb_hid -# Regulare keys +# Regular keys from adafruit_hid.keyboard import Keyboard from keyboard_layout_win_fr import KeyboardLayout from keycode_win_fr import Keycode -# multimedia keys -# ~ from adafruit_hid.consumer_control import ConsumerControl -# ~ from adafruit_hid.consumer_control_code import ConsumerControlCode -# ~ cc = ConsumerControl(usb_hid.devices) +# When in ALT mode, buttons use an alternative keycode. +ALT = False # KB setup keyboard = Keyboard(usb_hid.devices) keyboard_layout = KeyboardLayout(keyboard) # Buttons setup -# Change GPIOs according to HW buttons_gpio = { -# name GPIO Keycode State DigitalIO (switch) - "red" : dict(gpio=board.GP18, keycode=Keycode.D, state=False, DIO=None), - "green" : dict(gpio=board.GP19, keycode=Keycode.N, state=False, DIO=None), - "blue" : dict(gpio=board.GP16, keycode=Keycode.J, state=False, DIO=None), - "black" : dict(gpio=board.GP20, keycode=Keycode.E, state=False, DIO=None), - "yellow": dict(gpio=board.GP17, keycode=Keycode.B, 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)) +# name GPIO Keycode_1 Keycode_2(ALT mode) State DigitalIO (switch) + "red" : dict(gpio=board.GP18, keycode_1=Keycode.DELETE, keycode_2=Keycode.E, 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_1=Keycode.RIGHT_ARROW, keycode_2=Keycode.DOWN_ARROW, 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_1=Keycode.LEFT_ARROW,keycode_2=Keycode.UP_ARROW,state=False, 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 @@ -60,14 +58,32 @@ btn_scan_delay = 1/200 while True: 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']: - keyboard.press(buttons_gpio[btn]['keycode']) - buttons_gpio[btn]['state'] = not buttons_gpio[btn]['state'] + if ALT: + 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]: - 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']: - keyboard.release(buttons_gpio[btn]['keycode']) - buttons_gpio[btn]['state'] = not buttons_gpio[btn]['state'] + if ALT: + 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]: - buttons_gpio[btn]['switch_setup']['DIO'].value = False - time.sleep(btn_scan_delay) \ No newline at end of file + if buttons_gpio[btn]['switch_setup']['DIO'].value: + buttons_gpio[btn]['switch_setup']['DIO'].value = False + ALT = False + time.sleep(btn_scan_delay) diff --git a/readme.md b/readme.md index ecef33f..c9036ba 100644 --- a/readme.md +++ b/readme.md @@ -3,19 +3,18 @@ ![Outside](./picote-outside.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 - 2. Done +Copier le fichier 'code.py' et le répertoire 'lib' à la base du pico. -## Hadware setup +## Matériel nécessaire - * 5 push buttons - * 1 ON/OFF switch with indicator light or a separate LED - * 1 330Ω resistor + * 5 bouttons poussoirs + * 1 switch ON/OFF avec une LED intégrée ou en supplément. + * 1 rsistance 330Ω ![The crude diagram](./picote-s.jpg) \ No newline at end of file