Created
March 23, 2021 14:04
-
-
Save benevpi/1748a7d40b5f9ceb412e239399099f66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write your code here :-) | |
import board | |
import digitalio | |
import gamepad | |
import time | |
import usb_hid | |
from adafruit_hid.keyboard import Keyboard | |
from adafruit_hid.keycode import Keycode | |
kbd = Keyboard(usb_hid.devices) | |
B_UP = 1 << 0 | |
B_DOWN = 1 << 1 | |
B_LEFT = 1 << 2 | |
B_RIGHT = 1 << 3 | |
B_1 = 1 << 4 | |
B_2 = 1 << 5 | |
B_3 = 1 << 6 | |
B_4 = 1 << 7 | |
keycodes = [Keycode.UP_ARROW, Keycode.DOWN_ARROW, Keycode.LEFT_ARROW, Keycode.RIGHT_ARROW, | |
Keycode.X, Keycode.Z, Keycode.SPACE, Keycode.ENTER] | |
pad = gamepad.GamePad( | |
digitalio.DigitalInOut(board.GP12), | |
digitalio.DigitalInOut(board.GP14), | |
digitalio.DigitalInOut(board.GP9), | |
digitalio.DigitalInOut(board.GP15), | |
digitalio.DigitalInOut(board.GP16), | |
digitalio.DigitalInOut(board.GP17), | |
digitalio.DigitalInOut(board.GP18), | |
digitalio.DigitalInOut(board.GP20), | |
) | |
last_pressed = 0 | |
print("h343") | |
while True: | |
this_pressed = pad.get_pressed() | |
if (this_pressed != last_pressed): | |
#new keypresses | |
for i in range(8): | |
if (this_pressed & 1<<i) and not (last_pressed & 1<<i): | |
kbd.press(keycodes[i]) | |
if (last_pressed & 1<<i) and not (this_pressed & 1<<i): | |
kbd.release(keycodes[i]) | |
last_pressed = this_pressed | |
time.sleep(0.01) |
Author
benevpi
commented
Sep 25, 2021
via email
The gamepad module is in this git repo. I'm on mobile now so can't check,
but I think I put info about adding gamepad and the boot.py file in the
readme.
…On Sat, 25 Sep 2021, 2:57 am Michael Chrisco, ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
It looks like this example no longer works as gamepad is no longer
available.
https://github.com/adafruit/Adafruit_CircuitPython_HID/releases/tag/5.0.0
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/1748a7d40b5f9ceb412e239399099f66#gistcomment-3904521>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AHMR7ABS2FPX7R42K2LUCHTUDUUA5ANCNFSM5EXBNUCA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment