-
Notifications
You must be signed in to change notification settings - Fork 2
/
bluetoothmacro.ino
73 lines (68 loc) · 1.46 KB
/
bluetoothmacro.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <SoftwareSerial.h>
#include <Mouse.h>
char incomingByte = 0;
int x;
int y;
// TODO: More than just x and y state, will need to determine press, wheel, keyboard, etc.
char axis;
int aa_index;
int bb_index;
char aa[4];
char bb[4];
SoftwareSerial hc05(9,10);
void setup(){
delay(500);
Serial.begin(9600);
hc05.begin(9600);
Mouse.begin();
}
void loop(){
if (hc05.available()){
incomingByte = hc05.read();
// Serial.write(incomingByte);
if(incomingByte == 'x'){
axis = 'x';
}
else if(incomingByte == 'y'){
axis = 'y';
}
else if(incomingByte == 'z'){
axis = 'n';
int x1 = atoi(aa);
int y1 = atoi(bb);
// Serial.write("x");
// Serial.print(x1);
// Serial.print(aa);
// Serial.write("y");
// Serial.print(y1);
// Serial.print(bb);
for(int i = 0; i<30; i++){
Mouse.move(-127, -127);
}
for(int j = x1/127; j>0; j--){
Mouse.move(127, 0);
}
Mouse.move(x1%127, 0);
for(int k = y1/127; k>0; k--){
Mouse.move(0, 127);
}
Mouse.move(0, y1%127);
// Mouse.move(x1, y1);
memset(aa, 0, sizeof(aa));
memset(bb, 0, sizeof(bb));
aa_index = 0;
bb_index = 0;
}
else {
char ch1 = incomingByte;
if (axis == 'x'){
aa[aa_index] = ch1;
aa_index = aa_index + 1;
}
else if (axis == 'y'){
bb[bb_index] = ch1;
bb_index = bb_index + 1;
}
}
}
}