-
Notifications
You must be signed in to change notification settings - Fork 0
/
LaserTurret.ino
47 lines (38 loc) · 878 Bytes
/
LaserTurret.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
#include<Servo.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_Address 0x3C
Adafruit_SSD1306 oled(1);
Servo serX;
Servo serY;
String serialData;
String coordinates = "TEST";
void setup() {
serX.attach(11);
serY.attach(10);
Serial.begin(9600);
Serial.setTimeout(10);
oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
}
void loop() {
oled.clearDisplay();
oled.setTextColor(WHITE);
oled.setCursor(0,0);
oled.println(coordinates);
oled.display();
}
void serialEvent() {
serialData = Serial.readString();
coordinates = serialData;
serX.write(parseDataX(serialData));
serY.write(parseDataY(serialData));
}
int parseDataX(String data){
data.remove(data.indexOf("Y"));
data.remove(data.indexOf("X"), 1);
return data.toInt();
}
int parseDataY(String data){
data.remove(0,data.indexOf("Y") + 1);
return data.toInt();
}