-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathSketch_Arduino_leon_Mouse.ino
53 lines (50 loc) · 1.47 KB
/
Sketch_Arduino_leon_Mouse.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* HID KeyBoard Example
by: Jim Lindblom
date: 1/12/2012
license: MIT License - Feel free to use this code for any purpose.
No restrictions. Just keep this license if you go on to use this
code in your future endeavors! Reuse and share.
This is very simplistic code that allows you to send a 'z' with
a momentary pushbutton.
*/
#include <Mouse.h>
int buttonPin = 9; // Set a button to any pin
int y;
int i;
int l;
int x;
String list;
void setup()
{
Serial.begin(115200);
Serial.setTimeout(1);
// pinMode(buttonPin, INPUT); // Set the button as an input
digitalWrite(buttonPin, HIGH); // Pull the button high
delay(1000); // short delay to let outputs settle
Mouse.begin(); //Init mouse emulation
}
void loop()
{
if ( Serial.available()) {
list = Serial.readStringUntil('\n'); // Use readStringUntil to avoid the 1 second delay.
if (list == "l") {
Mouse.click(MOUSE_LEFT);
}
if (list == "r") {
Mouse.click(MOUSE_RIGHT);
}
else {
i = list.indexOf(";");
l = list.length();
x = list.substring(0,i).toInt();
y = list.substring(i+1,l).toInt();
Serial.println(x + " | " + y);
}
}
//delay(1000); // delay so there aren't a kajillion z's
Mouse.move(x, y, 0); // move mouse on y axis
//delay(1000); // delay so there aren't a kajillion z's
//Mouse.move(x, 0, 0); // move mouse on x axis
x = 0;
y = 0;
}