Skip to content

Instantly share code, notes, and snippets.

@Marcin648
Created July 27, 2020 00:55
Show Gist options
  • Save Marcin648/efb9c4f9f421e91023590d066214aed4 to your computer and use it in GitHub Desktop.
Save Marcin648/efb9c4f9f421e91023590d066214aed4 to your computer and use it in GitHub Desktop.
Simple code check resolution of joystick analog input
import pygame
import math
pygame.init()
pygame.joystick.init()
values = set()
j = pygame.joystick.Joystick(0)
print(j.get_name())
j.init()
last_count = 0
while True:
pygame.event.get()
value = j.get_axis(0)
values.add(value)
count = len(values)
if last_count != count:
print("Values: %s Bits: %s" % (count, math.ceil(math.log2(count+1))))
last_count = count
pygame.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment