Datasheet

the joystick because the joystick sits at the center of this range, 1.66, and the + and - of each axis is above and below
this number. Since we need to have thresholds in our code, we're going to map that range of 0-3.29 to while numbers
between 0-20.0 using this helper function. That way we can simplify our code and use larger ranges for our thresholds
instead of trying to figure out tiny decimal number changes.
Main Loop
First we assign x and y to read the voltages from x_axis and y_axis .
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-itsybitsy-nrf52840-express Page 162 of 179