Circuitpython Hid Mouse Helpers - Adafruit Feather M4 Express Manual

Table of Contents

Advertisement

To use this demo, simply move the joystick around. The mouse will move slowly if you move the joystick a little off
center, and more quickly if you move it as far as it goes. Press down on the joystick to click the mouse. Awesome! Now
let's take a look at the code.
Create the Objects and Variables
First we create the mouse object.
Next, we set
and
x_axis
The x and y axis on the joystick act like 2 potentiometers. We'll be using them just like we did in
In
(https://adafru.it/Bep). We set
potentiometers. We assign

CircuitPython HID Mouse Helpers

First we have the
get_voltage()
learned about it in Analog In
Second, we have
steps(axis)
the
variable we assigned earlier. The potentiometer range is 0-3.29. This is a small range. It's even smaller with
step
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
and
x
y
© Adafruit Industries
to pins
and
y_axis
A0
A1
and
pot_min
pot_max
step = (pot_max - pot_min) / 20.0
helper so we can get the correct readings from the potentiometers. Look familiar? We
(https://adafru.it/Bep).
. To use it, you provide it with the axis you're reading. This is where we're going to use
to read the voltages from
https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51
. Then we set
to
select
to be the minimum and maximum voltage read from the
to use in a helper function.
and
.
x_axis
y_axis
, set it as input and give it a pullup.
A2
CircuitPython Analog
Page 164 of 183

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Feather M4 Express and is the answer not in the manual?

Related Products for Adafruit Feather M4 Express

Table of Contents

Save PDF