-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathface_detector.ino
59 lines (48 loc) · 1 KB
/
face_detector.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
#include <VarSpeedServo.h>
VarSpeedServo servo1;
String inputString = ""; // a string to hold incoming data
unsigned int cont=0;
void setup()
{
servo1.attach(9);
Serial.begin(115200);
Serial.println("Ready");
}
void loop()
{
signed int vel;
unsigned int pos;
if (Serial.available())
{
inputString = Serial.readStringUntil('!');
vel = inputString.toInt();
if(inputString.endsWith("x"))
{
if (vel > 2)
servo1.write(180, vel, false);
else if (vel < -2)
servo1.write(0, -vel, false);
else
{
pos = servo1.read();
servo1.write(pos, 255, false);
}
}
else if(inputString.endsWith("o"))
{
cont++;
if (cont >= 100)
{
pos = servo1.read();
servo1.write(90, 20, true);
cont = 0;
}
else
{
pos = servo1.read();
servo1.write(pos, 255, false);
}
}
inputString = "";
}
}