-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmidi2hid.ino
58 lines (51 loc) · 1.6 KB
/
midi2hid.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
54
55
56
57
58
#include "Mouse.h"
#include "Keyboard.h"
int mouseLeft = 0;
int mouseRight = 0;
int mouseUp = 0;
int mouseDown = 0;
void setup() {
delay(90000); // wait until linux side finishes to boot
Serial1.begin(115200);
}
void loop() {
if (Serial1.available() >= 2) {
char command = Serial1.read();
char value = Serial1.read();
switch (command) {
case 'L': mouseLeft = value; break;
case 'R': mouseRight = value; break;
case 'U': mouseUp = value; break;
case 'D': mouseDown = value; break;
case 'M':
if(value ==1){ Mouse.press(); } else { Mouse.release(); }
break;
case 'w':
case 's':
case 'a':
case 'd':
case 'j':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '0':
if(value ==1){ Keyboard.press(command); } else { Keyboard.release(command); }
break;
case 'X':
mouseLeft = 0;
mouseRight = 0;
mouseUp = 0;
mouseDown = 0;
Keyboard.releaseAll();
break;
}
}
if (mouseLeft != 0 or mouseUp != 0) { Mouse.move(mouseLeft, mouseUp); }
if (mouseRight != 0 or mouseDown != 0) { Mouse.move(mouseRight, mouseDown); }
}