Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Select Game = F1
- # Reset Game = F2
- # Color TV = F3
- # Black/White TV = F4
- # Left Player Difficulty A = F5
- # Left Player Difficulty B = F6
- # Right Player Difficulty A = F7
- # Right Player Difficulty B = F8
- # Reset/Select Combo = Left-Control + Q
- import uinput
- import RPi.GPIO as GPIO
- import time
- GPIO.setmode(GPIO.BCM) #GPIO.BCM uses the GPIO port name for reference
- GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(20, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(21, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
- # GPIO19 = Color/B&W
- # GPIO16 = Left Difficulty
- # GPIO20 = Right Difficulty
- # GPIO21 = Reset
- # GPIO26 = Select
- 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])
- # Booleans to keep track of the push buttons
- Reset = False
- Select = False
- while True:
- if (GPIO.input(16)): # L-Diff Changed State to A
- device.emit(uinput.KEY_F6, 0) # release F6 keyboard button
- device.emit(uinput.KEY_F5, 1) # press F5 keyboard button
- if (not GPIO.input(16)): # L-Diff Changed State to B
- device.emit(uinput.KEY_F5, 0) # release F5 keyboard button
- device.emit(uinput.KEY_F6, 1) # press F6 keyboard button
- if (GPIO.input(20)): # R-Diff Changed State to A
- device.emit(uinput.KEY_F8, 0) # release F8 keyboard button
- device.emit(uinput.KEY_F7, 1) # press F7 keyboard button
- if (not GPIO.input(20)): # R-Diff Changed State to B
- device.emit(uinput.KEY_F7, 0) # release F7 keyboard button
- device.emit(uinput.KEY_F8, 1) # press F8 keyboard button
- if (GPIO.input(19)): # Color/B&W Changed State to Color
- device.emit(uinput.KEY_F4, 0) # release F4 keyboard button
- device.emit(uinput.KEY_F3, 1) # press F3 keyboard button
- if (not GPIO.input(19)): # Color/B&W Changed State to B&W
- device.emit(uinput.KEY_F3, 0) # release F3 keyboard button
- device.emit(uinput.KEY_F4, 1) # press F4 keyboard button
- if (not Select) and (not GPIO.input(26)): # Select button pressed
- Select = True
- device.emit(uinput.KEY_F1, 1) # press F1 keyboard button
- if Select and GPIO.input(26): # Select button released
- Select = False
- device.emit(uinput.KEY_F1, 0) # F1 keyboard button released
- device.emit(uinput.KEY_Q, 0) # Q keyboard button released
- device.emit(uinput.KEY_LEFTCTRL, 0) # Left Control keyboard button released
- if (not Reset) and (not GPIO.input(21)): # Reset button pressed
- Reset = True
- device.emit(uinput.KEY_F2, 1) # press F2 keyboard button
- if Reset and GPIO.input(21): # Reset button released
- Reset = False
- device.emit(uinput.KEY_F2, 0) # F2 keyboard button released
- device.emit(uinput.KEY_Q, 0) # Q keyboard button released
- device.emit(uinput.KEY_LEFTCTRL, 0) # Left Control keyboard button released
- if Select and Reset:
- device.emit(uinput.KEY_LEFTCTRL, 1) # Left Control keyboard button pressed
- time.sleep(0.01)
- device.emit(uinput.KEY_Q, 1) # Q keyboard button pressed
- time.sleep(0.2) # Poll every 200ms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement