-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial.ino
37 lines (34 loc) · 971 Bytes
/
serial.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
void setup(){
Serial1.begin(38400); // According to the Teensy Docs, this is the RX1 & TX1 on my board.
// Serial itself corrosponds to the micro-usb port
}
String readSerial() {
String buf = "";
if (Serial1.available() > 0) {
while (true) {
while (Serial1.available() > 0) {
if (Serial1.peek() == '#') { // END of buffer
Serial1.read(); // Read it to clear.
return buf;
} else {
buf += (char) Serial1.read();
}
}
}
// Serial1.println("Partial Buffer Received");
}
return buf;
}
void loop(){
String cmd = readSerial();
delay(10);
if (cmd[0] == 'M') {
Serial1.println(cmd.substring(1,5) + "," + cmd.substring(5));
Mouse.move(cmd.substring(1,5).toInt(), cmd.substring(5).toInt());
} else if (cmd[0] == 'C') {
Mouse.set_buttons(cmd.substring(1,2).toInt(), 0, 0);
} else if (cmd != "") {
//Serial1.println("AAAA");
// this is bad
}
}