Mouse Continuous Drawing

Using the Mouse library, you can turn your Leonardo, Micro, or Due board into a device that is recognized from your computer as a mouse peripheral, with all the controls that a standard mouse has.

With this example you will be able to control with two potentiometers the mouse pointer and drawing lines on a processing application, like in the famous etch-a-sketch game.

This example according the other mouse examples uses a pushbutton to enable or disable the Arduino's mouse functionality. The on-board LED on digital pin 13 will turn on or off to indicate the activation state of the mouse.

The potentiometer has an absolute reference but the cursor movement is always relative. So every time the analog input is read, the cursor's position is updated relative to it's current position.

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 includes a pushbutton to toggle the mouse control state, so you can turn on and off mouse control.

Hardware Required

  • Arduino Leonardo, Micro, or Due board
  • Two 10 kOhm potentiometer
  • Two momentary pushbutton
  • Two 10 kOhm resistors

Software Required

  • none


Connect your Leonardo board to your computer with a micro-USB cable. The pushbutton that turns on and off the mouse is connected to pin D2, the pushbutton that behaves as left-click is connected to pin D3. The two potentiometer that correspods to the X and Y axes are connected respectively on the analog inputs A0 and A1.

click the images to enlarge

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Arduino Code

SORRY, There is an error at our code repository, please inform to

click the images to enlarge

See Also