Arduino Button Mouse Control Code
Using the Mouse library, you can controls a computer’s onscreen cursor with an Arduino Leonardo, Micro, or Due. This particular example uses a five pushbuttons to move the onscreen cursor. Four of the buttons are directional (up, down, left, right) and one is for a left mouse click
Cursor movement from the Arduino is always relative. Every time an input is read, the cursor’s position is updated relative to it’s current position.
Whenever one of the directional buttons is pressed, the Arduino will move the mouse, mapping a HIGH input to a range of 5 in the appropriate direction.
The fifth button is for controlling a left click from a mouse. When pressed, the board sends a press to the computer. When the button is released, the computer will recognize the event.
NB: When you use the Mouse.move() command, the Arduino takes over your computer’s cursor! To insure you don’t lose control of your computer while running a sketch with this function, make sure to set up a controller before you call Mouse.move(). This sketch only updates the cursor position when a button is pressed.
/* ButtonMouseControl Controls the mouse from five pushbuttons on an Arduino Leonardo or Micro. Hardware: * 5 pushbuttons attached to D2, D3, D4, D5, D6 The mouse movement is always relative. This sketch reads four pushbuttons, and uses them to set the movement of the mouse. WARNING: When you use the Mouse.move() command, the Arduino takes over your mouse! Make sure you have control before you use the mouse commands. created 15 Mar 2012 modified 27 Mar 2012 by Tom Igoe this code is in the public domain */
For more detail: Arduino Button Mouse Control Code
JLCPCB – Prototype 10 PCBs for $2 + 2 days Lead Time
China’s Largest PCB Prototype Enterprise, 300,000+ Customers & 10,000+ Online Orders Per Day
Inside a huge PCB factory: https://www.youtube.com/watch?v=_XCznQFV-Mw
This Post / Project can also be found using search terms:
- arduino mouse
- arduino uno mouse
- arduino led mouse pressed
- arduino mouse control