-
Notifications
You must be signed in to change notification settings - Fork 0
/
servo.cpp
44 lines (34 loc) · 819 Bytes
/
servo.cpp
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
Servo leftservo;
Servo rightservo;
int posL = 0;
int posR = 0;
int leftSpeed = 30;
int rightSpeed = 30;
bool on = false;
void setup() {
leftservo.attach(D0);
Particle.function("setposL", setPosL);
// Particle.variable("getposR", &posL, INT);
rightservo.attach(D1);
Particle.function("setposR", setPosR);
// Particle.variable("getposL", &posR, INT);
Particle.function("setpos", setPos);
}
void loop() {
}
int setPosL(String pstnL) {
posL = pstnL.toInt();
leftservo.write(90 + posL + 8);
return posL;
}
int setPosR(String pstnR) {
posR = pstnR.toInt();
rightservo.write(90 - posR);
return posR;
}
int setPos(String s) {
int commapos = s.indexOf(",");
setPosL(s.substring(0,commapos));
setPosR(s.substring(commapos+1, s.length()));
return 1;
}