|
| 1 | +import adafruit_cursor |
| 2 | +import board |
| 3 | +import digitalio |
| 4 | +import displayio |
| 5 | +from gamepadshift import GamePadShift |
| 6 | +from micropython import const |
| 7 | + |
| 8 | +# PyBadge Button Masks |
| 9 | +BUTTON_LEFT = const(128) |
| 10 | +BUTTON_UP = const(64) |
| 11 | +BUTTON_DOWN = const(32) |
| 12 | +BUTTON_RIGHT = const(16) |
| 13 | +BUTTON_A = const(2) |
| 14 | +BUTTON_B = const(1) |
| 15 | + |
| 16 | +# Initialize PyBadge Gamepad |
| 17 | +pad = GamePadShift(digitalio.DigitalInOut(board.BUTTON_CLOCK), |
| 18 | + digitalio.DigitalInOut(board.BUTTON_OUT), |
| 19 | + digitalio.DigitalInOut(board.BUTTON_LATCH)) |
| 20 | + |
| 21 | +# Create the display |
| 22 | +display = board.DISPLAY |
| 23 | + |
| 24 | +# Create the display context |
| 25 | +splash = displayio.Group(max_size=22) |
| 26 | + |
| 27 | +# initialize the mouse cursor object |
| 28 | +mouse_cursor = adafruit_cursor.Cursor(display, display_group=splash) |
| 29 | + |
| 30 | +# show displayio group |
| 31 | +display.show(splash) |
| 32 | + |
| 33 | +def check_dpad(d_pad_buttons): |
| 34 | + """Checks the directional pad for button presses.""" |
| 35 | + if d_pad_buttons & BUTTON_RIGHT: |
| 36 | + mouse_cursor.x += mouse_cursor.speed |
| 37 | + elif d_pad_buttons & BUTTON_LEFT: |
| 38 | + mouse_cursor.x -= mouse_cursor.speed |
| 39 | + if d_pad_buttons & BUTTON_DOWN: |
| 40 | + mouse_cursor.y += mouse_cursor.speed |
| 41 | + elif d_pad_buttons & BUTTON_UP: |
| 42 | + mouse_cursor.y -= mouse_cursor.speed |
| 43 | + |
| 44 | +is_pressed = False |
| 45 | +while True: |
| 46 | + display.wait_for_frame() |
| 47 | + pressed = pad.get_pressed() |
| 48 | + check_dpad(pressed) |
| 49 | + if is_pressed: |
| 50 | + if not pressed & (BUTTON_A | BUTTON_B): |
| 51 | + is_pressed = False |
| 52 | + continue |
| 53 | + if pressed & BUTTON_A: |
| 54 | + is_pressed = True |
| 55 | + if mouse_cursor.hide: |
| 56 | + mouse_cursor.hide = False |
| 57 | + else: |
| 58 | + mouse_cursor.hide = True |
0 commit comments