Next, we check to see when the state of the select button is
False
. It defaults to
True
when it is not pressed, so if the
state is
False
, the button has been pressed. When it's pressed, it sends the command to click the left mouse button.
The
time.sleep(0.2)
prevents it from reading multiple clicks when you've only clicked once.
Then we use the
steps()
function to set our mouse movement. There are two sets of two
if
statements for each axis.
Remember that
10
is the center step, as we've mapped the range
0-20
. The first set for each axis says if the joystick
moves 1 step off center (left or right for the x axis and up or down for the y axis), to move the mouse the appropriate
direction by 1 unit. The second set for each axis says if the joystick is moved to the lowest or highest step for each axis,
to move the mouse the appropriate direction by 8 units. That way you have the option to move the mouse slowly or
quickly!
To see what
step
the joystick is at when you're moving it, uncomment the
statements by removing the
#
from
the lines that look like
# print(steps(x))
, and connecting to the serial console to see the output. Consider only
uncommenting one set at a time, or you end up with a huge amount of information scrolling very quickly, which can be
difficult to read!
For more detail check out the documentation at https://circuitpython.readthedocs.io/projects/hid/en/latest/
© Adafruit Industries
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
Page 165 of 183
Содержание Feather M4 Express
Страница 1: ...Adafruit Feather M4 Express Created by lady ada Last updated on 2019 03 04 10 41 14 PM UTC...
Страница 5: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 10 of 183...
Страница 58: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 63 of 183...
Страница 164: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 169 of 183...
Страница 168: ...Adafruit Industries https learn adafruit com adafruit feather m4 express atsamd51 Page 173 of 183...