
if (vertValue
!= 0)
Mouse.move(0,
vertValue/sensitivity,
0);
//
move
mouse
o
n
y
axis
if (horzValue
!= 0)
Mouse.move(horzValue/sensitivity,
0,
0);
//
move
mouse
o
n
x
axis
if ((digitalRead(selPin)
== 0)
&& (!mouseClickFlag))
//
if
the
joystick
button
is
pressed
{
mouseClickFlag
= 1;
Mouse.press(MOUSE_LEFT);
//
click
the
left
button
down
}
else if ((digitalRead(selPin))&&(mouseClickFlag))
//
if
the
joystick
button
is
not
pressed
{
mouseClickFlag
= 0;
Mouse.release(MOUSE_LEFT);
//
release
the
left
button
}
}
This sketch is set up so that an analog joystick connected to analog pins A0
and A1 can be used to move your mouse cursor.
The
loop()
of this code continuously monitors the horizontal and vertical
analog values of the joystick and sends the
Mouse.move()
command based
on what it reads. It’ll move the mouse in steps, depending on what the
sensitivity variable is set to. With sensitivity set to 2, the cursor will move in
either 1 or 2 pixel steps.
The select switch on the joystick is used to control the mouse left click.
Notice this code is using
Mouse.press()
and
Mouse.release()
, rather
than just calling a single
Mouse.click()
. This requires a bit more coding,
but it allows you to do things like drag-and-drop, double click, etc.
For more HID example code, check out the Arduino-supplied examples
under the ‘File’ > ‘Examples’ > ‘09.USB’ menu.
Troubleshooting and FAQ
On this page you’ll find troubleshooting tips and FAQs. Here’s a directory of
the subjects covered:
•
Troubleshooting
◦
Serial Port Not Showing Up in “Tools > Board” menu
◦
How to Reset to Bootloader
◦
How to Revive a “Bricked” Pro Micro
Page 22 of 27