I wired up a couple of push buttons between D3 and Gnd, and D4 and Gnd. I had hoped to use the Gamepad library as that seems to be the right kind of thing to use. However, the AdaFruit library download does not contain Gamepad, and I could not be bothered to compile it from source.
So I'm just checking the button value directly in a loop and that seems to work correctly. I borrowed an idea from AdaFruit regarding setting up the buttons, using an array. I'll likely tweek this a bit before combining it into the original game code.
import board
import digitalio
import time
buttonpins = [board.D3, board.D4]
buttons = []
for pin in buttonpins:
button = digitalio.DigitalInOut(pin)
button.direction = digitalio.Direction.INPUT
button.pull = digitalio.Pull.UP
buttons.append(button)
print("FizzBuzz! Press any key")
while True:
# check each button
for button in buttons:
if (not button.value): # pressed?
print(buttons.index(button))
time.sleep(0.2)