序言
本代码是在这个大佬的基础上进行修改,主要目的是针对树莓派小车的移动以及视角的控制,所以就只保留了摇杆的控制,舍弃了按键,想要完整版的可以去找大佬的代码
正文
import pygame
pygame.init()
pygame.joystick.init()
done=False
while (done != True):
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
joystick_count = pygame.joystick.get_count()
for i in range(joystick_count):
joystick = pygame.joystick.Joystick(i)
joystick.init()
axes = joystick.get_numaxes()
print('================')
for i in range(axes):
axis = joystick.get_axis(i)
print(axis)