/*
Button Mouse Control
For Leonardo and Due boards only .Controls the mouse from
five pushbuttons on an Arduino Leonardo, Micro or Due.
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.
*/
#include "Mouse.h"
#include "USBHID"
// set pin numbers for the five buttons:
const int middlebutton = 42;
const int rightButton = 6;
const int mouseButton = 40;
int responseDelay = 10; // response delay of the mouse, in ms
void setup() {
// initialize the buttons' inputs:
pinMode(middlebutton, INPUT);
pinMode(rightButton, INPUT);
pinMode(mouseButton, INPUT);
// initialize mouse control:
Mouse.begin();
}
void loop() {
// read the buttons:
int click2 = digitalRead(middlebutton);
int click1 = digitalRead(leftButton);
int click3 = digitalRead(mouseButton);
}
// if theS mouse button is pressed:
if (click1 == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
} else { // else the mouse button is not pressed:
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(MOUSE_LEFT);
}
if (click2 == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_MIDDLE) {
Mouse.press(MOUSE_MIDDLE);
}
} else { // else the mouse button is not pressed:
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_MIDDLE) {
Mouse.release(MOUSE_MIDDLE);
}
if (click3 == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_RIGHT) {
Mouse.press(MMOUSE_RIGHT);
}
} else { // else the mouse button is not pressed:
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_RIGHT) {
Mouse.release(MOUSE_RIGHT);
}
}
}
Loading
esp32-s2-devkitm-1
esp32-s2-devkitm-1