-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mercury 2021 Controller V2.py
57 lines (46 loc) · 1.43 KB
/
Mercury 2021 Controller V2.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#Version 2.0
import math
import pygame
pygame.init()
clock = pygame.time.Clock()
pygame.joystick.init()
DEAD_ZONE_Y = 0.15
done = False
while not done:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done = True
elif event.type == pygame.JOYBUTTONDOWN:
print("Joystick button pressed.")
elif event.type == pygame.JOYBUTTONUP:
print("Joystick button released.")
joystick_count = pygame.joystick.get_count()
for i in range(joystick_count):
joystick = pygame.joystick.Joystick(i)
joystick.init()
#Joysticks
axes = joystick.get_numaxes()
axis = []
for i in range(axes):
axis.append(float('%.3f'% (joystick.get_axis(i))))
if abs(axis[i]) < DEAD_ZONE_Y:
axis[i] = 0
#print(axis)
#Buttons
buttons = joystick.get_numbuttons()
button = []
for i in range(buttons):
button.append(joystick.get_button(i))
print(button)
#Hats
hats = joystick.get_numhats()
hat = []
for i in range(hats):
hat.append(joystick.get_hat(i))
#print(hat)
if (joystick.get_button(7) == 1):
done = True
pygame.quit()
break
clock.tick(20)
print("program done")