joystick-souris.ino

Arduino Esplora — Board Fiche · File : joystick-souris.ino · Language : Arduino · Use case : Utiliser l'Esplora comme souris USB grâce à l'ATmega32U4

Like the Leonardo, the Esplora can enumerate a HID mouse: the joystick becomes a pointer, its center button a click. A giant ergonomic mouse, or a driverless pointer for a shop screen.

Hardware required

An Arduino Esplora (ATmega32U4, 5 V) with its onboard sensors: joystick, 4 buttons, slider, RGB LED, buzzer, light, temperature, sound and accelerometer. None.

Wiring

USB cable to the computer.

How it works

Joystick deviation divided by 32 sets pointer speed; readJoystickSwitch reports the center press (near 1023). In the Arduino IDE, select « Arduino Esplora »; add the « Esplora » library from the Library Manager to reach the onboard sensors.

Going further

Add the diamond buttons for right/middle click, or the slider for wheel scrolling.

joystick-souris.ino

// L'Esplora (comme la Leonardo) est un peripherique HID : souris.
#include <Mouse.h>
#include <Esplora.h>

void setup() {
  Mouse.begin();
}

void loop() {
  int jx = Esplora.readJoystickX() / 32; // -16..16 px
  int jy = Esplora.readJoystickY() / 32;
  if (abs(jx) > 1 || abs(jy) > 1) Mouse.move(jx, jy);
  if (Esplora.readJoystickSwitch() > 512) Mouse.click(MOUSE_LEFT);
  delay(20);
}

← Back to the board