photobooth/buttons.py

36 lines
912 B
Python

import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
import board
import digitalio
from time import sleep
# Set up a keyboard device.
kbd = Keyboard(usb_hid.devices)
buttonpins = [board.GP27, board.GP28, board.GP4, board.GP5,
board.GP21, board.GP19, board.GP12, board.GP10,
board.GP20, board.GP18, board.GP13, board.GP11]
buttons = []
pressed = [False for i in range(12)]
for i, b in enumerate(buttonpins):
buttons.append(digitalio.DigitalInOut(b))
buttons[i].switch_to_input(pull=digitalio.Pull.UP)
print(Keycode.B)
while True:
for i, b in enumerate(buttons):
if buttons[i].value == 0:
if pressed[i] == False:
print("Button ", i)
kbd.send(Keycode.A + i)
pressed[i] = True
else:
pressed[i] = False
sleep(0.05)