Open EloiStree opened 1 week ago
https://amzn.to/3Z7P9cj
# https://github.com/EloiStree/HelloInput/issues/284 print("Hello Wow") import board import digitalio import usb_hid from adafruit_hid.keyboard import Keyboard from adafruit_hid.keycode import Keycode import time print("Anti Spam...") time.sleep(3) print("Ready :)") # Set up keyboard keyboard = Keyboard(usb_hid.devices) pin_10_left = digitalio.DigitalInOut(board.GP13) pin_10_left.direction = digitalio.Direction.INPUT pin_10_left.pull = digitalio.Pull.UP pin_11_right = digitalio.DigitalInOut(board.GP11) pin_11_right.direction = digitalio.Direction.INPUT pin_11_right.pull = digitalio.Pull.UP pin_12_up = digitalio.DigitalInOut(board.GP12) pin_12_up.direction = digitalio.Direction.INPUT pin_12_up.pull = digitalio.Pull.UP pin_13_down = digitalio.DigitalInOut(board.GP10) pin_13_down.direction = digitalio.Direction.INPUT pin_13_down.pull = digitalio.Pull.UP pin_09_jump = digitalio.DigitalInOut(board.GP9) pin_09_jump.direction = digitalio.Direction.INPUT pin_09_jump.pull = digitalio.Pull.UP bool_is_joystick_left = False bool_is_joystick_right = False bool_is_joystick_up = False bool_is_joystick_down = False bool_is_jumping_current=False bool_is_joystick_left_previous = False bool_is_joystick_right_previous = False bool_is_joystick_up_previous = False bool_is_joystick_down_previous = False bool_is_jumping_previous=False while True: bool_print_joystick=False bool_is_joystick_left_previous = bool_is_joystick_left bool_is_joystick_right_previous = bool_is_joystick_right bool_is_joystick_up_previous = bool_is_joystick_up bool_is_joystick_down_previous = bool_is_joystick_down bool_is_jumping_previous = bool_is_jumping_current bool_is_joystick_left =not pin_10_left.value bool_is_joystick_right = not pin_11_right.value bool_is_joystick_up =not pin_12_up.value bool_is_joystick_down = not pin_13_down.value bool_is_jumping_current =not pin_09_jump.value if bool_is_jumping_current != bool_is_jumping_previous: bool_is_jumping_previous = bool_is_jumping_current if bool_is_jumping_current: print("Joystick Jump Start") keyboard.press(Keycode.SPACE) else: print("Joystick Jump End") keyboard.release(Keycode.SPACE) if bool_is_joystick_left != bool_is_joystick_left_previous: bool_is_joystick_left_previous = bool_is_joystick_left if bool_is_joystick_left: print("Joystick Left Start") keyboard.press(Keycode.LEFT_ARROW) else: print("Joystick Left End") keyboard.release(Keycode.LEFT_ARROW) if bool_is_joystick_right != bool_is_joystick_right_previous: bool_is_joystick_right_previous = bool_is_joystick_right if bool_is_joystick_right: print("Joystick Right Start") keyboard.press(Keycode.RIGHT_ARROW) else: print("Joystick Right End") keyboard.release(Keycode.RIGHT_ARROW) if bool_is_joystick_up != bool_is_joystick_up_previous: bool_is_joystick_up_previous = bool_is_joystick_up if bool_is_joystick_up: print("Joystick Up Start") keyboard.press(Keycode.UP_ARROW) else: print("Joystick Up End") keyboard.release(Keycode.UP_ARROW) if bool_is_joystick_down != bool_is_joystick_down_previous: bool_is_joystick_down_previous = bool_is_joystick_down if bool_is_joystick_down: print("Joystick Down Start") keyboard.press(Keycode.DOWN_ARROW) else: print("Joystick Down End") keyboard.release(Keycode.DOWN_ARROW)
https://amzn.to/3Z7P9cj