-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkit_input.py
42 lines (37 loc) · 1.01 KB
/
kit_input.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
40
41
42
import digitalio
import board
EVENT_UP = 0
EVENT_DOWN = 1
EVENT_APPLY = 2
buttonA = digitalio.DigitalInOut(board.D17)
buttonA.switch_to_input()
pad_up = digitalio.DigitalInOut(board.D23)
pad_up.switch_to_input()
pad_down = digitalio.DigitalInOut(board.D27)
pad_down.switch_to_input()
pad_up_hold = False
pad_down_hold = False
#event_apply = pygame.event.Event(pygame.KEYDOWN, key=
def get_joystick_event():
print('CHECK EVENT')
global pad_up_hold
global pad_down_hold
# The buttons are active low, so "not value" means it's pressed
if not buttonA.value:
print('BUTTON')
return EVENT_APPLY
if not pad_up.value: # just button A pressed
print('UP')
if not pad_up_hold:
pad_up_hold = True
return EVENT_UP
else:
pad_up_hold = False
if not pad_down.value:
print('DOWN')
if not pad_down_hold:
pad_down_hold = True
return EVENT_DOWN
else:
pad_down_hold = False
return None