Here is my python code https://github.com/aeropunk/Arduino-Python-4-Axis-Servo/blob/master/multijoystick.py
Here is a part of the whole code to show actually which one I am using
# Assign actions for Button DOWN events
if e.type == pygame.JOYBUTTONDOWN:
# Button 1 (trigger)
if (e.dict['button'] == 0):
print "Trriger Down"
# Set pin 13 LED to HIGH for digital on/off demo
# Button 2
if (e.dict['button'] == 1):
print "Button 2 Down"
servo.move(5, 180) #This is used to select servo no. 5 and rotate it to 180 degrees
# Button 4
if (e.dict['button'] == 3):
servo.move(5, 0) # #This is used to select servo no. 5 and rotate it back to 0 degrees
print "Button 4 Down"
Here button == 1 will rotate the servo clockwise and button == 3 will rotate that servo anticlockwise . Also there is another file servo.py where there is move(servo, angle) function. here servo means number which sends data to switch statement below.
Here is my arduino code https://raw.github.com/aeropunk/Arduino-Python-4-Axis-Servo/master/MultipleSerialServoControl.pde
Below is a part of my ardiono code
if(pos == 180)
//What code should be written to rotate it clockwise as long as the button is pressed
if(pos == 0)
////What code should be written to rotate it anti-clockwise as long as the button is pressed
I have used the switch statement because its easier to communicate with usb gamepad through serial.read()