-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActorServo.cpp
More file actions
60 lines (47 loc) · 1.09 KB
/
ActorServo.cpp
File metadata and controls
60 lines (47 loc) · 1.09 KB
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
60
/*
http://www.ardumote.com
Copyright (c) 2012 Suat Özgür
http://opensource.org/licenses/MIT
*/
#include "Arduino.h"
#include "ActorServo.h"
void ActorServo::setup(char* sName, int nDigitalPin) {
setName(sName);
nPin = nDigitalPin;
nDeviceTypeID = 8;
}
bool ActorServo::exec(char* p1) {
int params[3];
int paramCount = 0;
char* pch;
pch = strtok (p1, ",");
while (pch != NULL) {
params[paramCount++] = atoi(pch);
Serial.print(pch);
Serial.print(" ");
Serial.println(params[paramCount-1]);
pch = strtok (NULL, ",");
}
myservo.attach(nPin);
delay(500);
if (params[0]>179) {
myservo.write(179);
} else if (params[0] <= 0) {
myservo.write(0);
} else {
myservo.write(params[0]);
}
Serial.print("delay...");
Serial.println(params[1]);
delay(params[1] * 1000);
if (params[2]>179) {
myservo.write(179);
} else if (params[2] <= 0) {
myservo.write(0);
} else {
myservo.write(params[2]);
}
delay(2000);
myservo.detach();
return true;
}