User Manual
For this example, we've wired up a 2-axis thumb joystick with a select button. We use this to emulate the mouse
movement and the mouse left-button click. To wire up this joytick:
Connect VCC on the joystick to the 3V on your board. Connect ground to ground.
Connect Xout on the joystick to pin A0 on your board.
Connect Yout on the joystick to pin A1 on your board.
Connect Sel on the joystick to pin A2 on your board.
Remember, Trinket's pins are labeled differently. Check the Trinket Pinouts page (https://adafru.it/AMd) to verify your
wiring.
def get_voltage(pin):
return (pin.value * 3.3) / 65536
def steps(axis):
""" Maps the potentiometer voltage range to 0-20 """
return round((axis - pot_min) / step)
while True:
x = get_voltage(x_axis)
y = get_voltage(y_axis)
if select.value is False:
mouse.click(Mouse.LEFT_BUTTON)
time.sleep(0.2) # Debounce delay
if steps(x) > 11.0:
# print(steps(x))
mouse.move(x=1)
if steps(x) < 9.0:
# print(steps(x))
mouse.move(x=-1)
if steps(x) > 19.0:
# print(steps(x))
mouse.move(x=8)
if steps(x) < 1.0:
# print(steps(x))
mouse.move(x=-8)
if steps(y) > 11.0:
# print(steps(y))
mouse.move(y=-1)
if steps(y) < 9.0:
# print(steps(y))
mouse.move(y=1)
if steps(y) > 19.0:
# print(steps(y))
mouse.move(y=-8)
if steps(y) < 1.0:
# print(steps(y))
mouse.move(y=8)
© Adafruit Industries https://learn.adafruit.com/adafruit-metro-m4-express-airlift-wifi Page 162 of 187