-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.ino
37 lines (30 loc) · 709 Bytes
/
sample.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() {
Serial.begin(115200);
}
String data = "";
int indexX, indexY, indexAst;
String x, y;
void loop() {
// format: ,1,-10*
// format: ,x,y*
if (Serial.available() > 0) {
char d = Serial.read();
Serial.println(d);
// * means the end of the data
if (d == '*') {
Serial.println(data);
indexX = data.indexOf(',');
indexY = data.indexOf(',', indexX + 1);
indexAst = data.indexOf('*');
x = data.substring(indexX + 1, indexY);
y = data.substring(indexY + 1, indexAst - 1);
Serial.print("X: ");
Serial.println(x);
Serial.print("Y: ");
Serial.println(y);
data = "";
} else {
data += d;
}
}
}