
In pygame 2 the X360 controller mapping has 6 Axes, 11 buttons and 1 hat. X-Box 360 Controller (name: "Xbox 360 Controller") Below are a couple of mappings for two popular game pads.Īxis and hat mappings are listed from -1 to +1. quit ()Ĭontroller mappings are drawn from the underlying SDL library which pygame uses and they differīetween pygame 1 and pygame 2. # If you forget this line, the program will 'hang' # on exit if running from IDLE. unindent () # ALL CODE TO DRAW SHOULD GO ABOVE THIS COMMENT # Go ahead and update the screen with what we've drawn. tprint ( screen, "Number of joysticks: ". Don't put other drawing commands # above this, or they will be erased with this command. JOYBUTTONUP : print ( "Joystick button released." ) # DRAWING STEP # First, clear the screen to white. JOYBUTTONDOWN : print ( "Joystick button pressed." ) elif event. done = True # Flag that we are done so we exit this loop.
#Usb joystick controller adafruit how to
your own I2C slave device using a PIC microcontroller, and how to control it with a Raspberry Pi. textPrint = TextPrint () # - Main Program Loop - while not done : # EVENT PROCESSING STEP # Possible joystick actions: JOYAXISMOTION, JOYBALLMOTION, JOYBUTTONDOWN, # JOYBUTTONUP, JOYHATMOTION for event in pygame. CLUE from Adafruit: A Smart Solution for IoT Projects. done = False # Used to manage how fast the screen updates.

set_caption ( "My Game" ) # Loop until the user clicks the close button.

init () # Set the width and height of the screen (width, height). line_height = 15 def indent ( self ): self. render ( textString, True, BLACK ) screen.

Font ( None, 20 ) def tprint ( self, screen, textString ): textBitmap = self. class TextPrint ( object ): def _init_ ( self ): self. # It has nothing to do with the joysticks, just outputting the # information. Color ( 'white' ) # This is a simple class that will help us print to the screen.
