daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pigpio
  2.  
  3. # servo/gpio control
  4. pi = pigpio.pi()
  5.  
  6. # choose your pins
  7. tilt = 17
  8. pan = 27
  9.  
  10. # center the servos
  11. x = 1250
  12. y = 1250
  13.  
  14. # want to display ALL info?
  15. debug = False
  16.  
  17. if debug:
  18.         for device in evdev.list_devices():
  19.                 print(evdev.InputDevice(device))
  20.  
  21.         input("Press Enter to continue ...")
  22.  
  23. # create object to read input - specify YOUR device
  24. controller = InputDevice('/dev/input/event0')
  25.  
  26. # what are the controller details?
  27. if debug:
  28.     print(controller)
  29.  
  30. # read controller info in an infinite loop
  31. for event in controller.read_loop():
  32.  
  33.     # here I am looking for the start button
  34.     # so I can quit
  35.     if event.type == 1:
  36.         exit()
  37.  
  38.     # set as true above if you want to look up
  39.     # different button values
  40.     if debug:
  41.         print("\n\nEvent Type:{}".format(event.type))
  42.         print("Event Code:{}".format(event.code))
  43.         print("Event Value:{}".format(event.value))
  44.  
  45.     # look for pad moves
  46.     if event.type == 3:
  47.  
  48.         # up and down is 17
  49.         if event.code == 17:
  50.             if event.value == -1:
  51.                 print("\n\n\nPad Up\n")
  52.                 if y > 600: y -= 100
  53.             if event.value == 1:
  54.                 print("\n\n\nPad Down\n")
  55.                 if y < 2400:y += 100
  56.  
  57.         pi.set_servo_pulsewidth(tilt, y)
  58.  
  59.         # left and right is 16
  60.         if event.code == 16:
  61.             if event.value == -1:
  62.                 print("\n\n\nPad Left\n")
  63.                 if x > 400: x -= 100
  64.  
  65.             if event.value == 1:
  66.                 print("\n\n\nPad Right\n")
  67.                 if x < 2400: x += 100
  68.  
  69.         pi.set_servo_pulsewidth(pan, x)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top