-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
39 lines (31 loc) · 867 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Import the libraries
import time
import board
from digitalio import DigitalInOut, Direction, Pull
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
import usb_hid
# define output LED
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
# flash the LED when booting
for x in range(0, 5):
led.value = False
time.sleep(0.2)
led.value = True
time.sleep(0.2)
# configure device as keyboard
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)
# define buttons
d0 = DigitalInOut(board.D0)
d0.direction = Direction.INPUT
d0.pull = Pull.UP
# loop forever
while True:
if not d0.value:
led.value = False # led on
kbd.send(Keycode.ENTER)
time.sleep(0.2) # debounce delay
led.value = True # led off