EasyManua.ls Logo

Adafruit Feather M4 Express - Page 158

Adafruit Feather M4 Express
178 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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 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-feather-m4-express-atsamd51 Page 163 of 183

Table of Contents

Related product manuals