User Manual

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 print 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-metro-m4-express-airlift-wifi Page 164 of 187