Skip to content

Instantly share code, notes, and snippets.

@akshar100
Created April 11, 2012 10:15
Show Gist options
  • Save akshar100/2358398 to your computer and use it in GitHub Desktop.
Save akshar100/2358398 to your computer and use it in GitHub Desktop.
Pygame Joystick control
# Author: Akshar Prabhu Desai
# Date: 20/04/2011
# Objective: To interface FB5 with joystick
#
import pygame
import inspect
import math
import time
exec(open("functionList.py").read());
pygame.init()
joystick_count=pygame.joystick.get_count()
if joystick_count == 0:
# No joysticks!
print ("Error, I didn't find any joysticks.")
else:
# Use joystick #0 and initialize it
my_joystick = pygame.joystick.Joystick(0)
my_joystick.init()
clock = pygame.time.Clock()
tick =0;
done=False
while done==False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
done=True
continue
##GET ANALOG VALUES OF JOYSTICK##
vert_axis_pos= my_joystick.get_axis(1)
hor_axis_pos= my_joystick.get_axis(0)
#ROUNDED OFF VALUES OF GAME CONTROLLER#
vert_axis_pos= math.floor(vert_axis_pos*10)
hor_axis_pos= math.floor(hor_axis_pos*10)
print(hor_axis_pos)
clock.tick()
pygame.quit ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment