Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2017
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. # Select Game = F1
  2. # Reset Game = F2
  3. # Color TV = F3
  4. # Black/White TV = F4
  5. # Left Player Difficulty A = F5
  6. # Left Player Difficulty B = F6
  7. # Right Player Difficulty A = F7
  8. # Right Player Difficulty B = F8
  9.  
  10. # Reset/Select Combo = Left-Control + Q
  11.  
  12.  
  13. import uinput
  14. import RPi.GPIO as GPIO
  15. import time
  16.  
  17. GPIO.setmode(GPIO.BCM) #GPIO.BCM uses the GPIO port name for reference
  18.  
  19. GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  20. GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  21. GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  22. GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  23. GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
  24.  
  25. # GPIO19 = Color/B&W
  26. # GPIO16 = Left Difficulty
  27. # GPIO20 = Right Difficulty
  28. # GPIO21 = Reset
  29. # GPIO26 = Select
  30.  
  31.  
  32. device = uinput.Device([uinput.KEY_F1, uinput.KEY_F2, uinput.KEY_F3, uinput.KEY_F4, uinput.KEY_F5, uinput.KEY_F6, uinput.KEY_F7, uinput.KEY_F8, uinput.KEY_Q, uinput.KEY_LEFTCTRL, uinput.KEY_ESC])
  33.  
  34.  
  35. # Booleans to keep track of the push buttons
  36. Reset = False
  37. Select = False
  38.  
  39.  
  40. while True:
  41. if (GPIO.input(16)): # L-Diff Changed State to A
  42. device.emit(uinput.KEY_F6, 0) # release F6 keyboard button
  43. device.emit(uinput.KEY_F5, 1) # press F5 keyboard button
  44.  
  45. if (not GPIO.input(16)): # L-Diff Changed State to B
  46. device.emit(uinput.KEY_F5, 0) # release F5 keyboard button
  47. device.emit(uinput.KEY_F6, 1) # press F6 keyboard button
  48.  
  49. if (GPIO.input(20)): # R-Diff Changed State to A
  50. device.emit(uinput.KEY_F8, 0) # release F8 keyboard button
  51. device.emit(uinput.KEY_F7, 1) # press F7 keyboard button
  52.  
  53. if (not GPIO.input(20)): # R-Diff Changed State to B
  54. device.emit(uinput.KEY_F7, 0) # release F7 keyboard button
  55. device.emit(uinput.KEY_F8, 1) # press F8 keyboard button
  56.  
  57. if (GPIO.input(19)): # Color/B&W Changed State to Color
  58. device.emit(uinput.KEY_F4, 0) # release F4 keyboard button
  59. device.emit(uinput.KEY_F3, 1) # press F3 keyboard button
  60.  
  61. if (not GPIO.input(19)): # Color/B&W Changed State to B&W
  62. device.emit(uinput.KEY_F3, 0) # release F3 keyboard button
  63. device.emit(uinput.KEY_F4, 1) # press F4 keyboard button
  64.  
  65. if (not Select) and (not GPIO.input(26)): # Select button pressed
  66. Select = True
  67. device.emit(uinput.KEY_F1, 1) # press F1 keyboard button
  68.  
  69. if Select and GPIO.input(26): # Select button released
  70. Select = False
  71. device.emit(uinput.KEY_F1, 0) # F1 keyboard button released
  72. device.emit(uinput.KEY_Q, 0) # Q keyboard button released
  73. device.emit(uinput.KEY_LEFTCTRL, 0) # Left Control keyboard button released
  74.  
  75. if (not Reset) and (not GPIO.input(21)): # Reset button pressed
  76. Reset = True
  77. device.emit(uinput.KEY_F2, 1) # press F2 keyboard button
  78.  
  79. if Reset and GPIO.input(21): # Reset button released
  80. Reset = False
  81. device.emit(uinput.KEY_F2, 0) # F2 keyboard button released
  82. device.emit(uinput.KEY_Q, 0) # Q keyboard button released
  83. device.emit(uinput.KEY_LEFTCTRL, 0) # Left Control keyboard button released
  84.  
  85. if Select and Reset:
  86. device.emit(uinput.KEY_LEFTCTRL, 1) # Left Control keyboard button pressed
  87. time.sleep(0.01)
  88. device.emit(uinput.KEY_Q, 1) # Q keyboard button pressed
  89.  
  90. time.sleep(0.2) # Poll every 200ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement