-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinmoov_jaw.ino
38 lines (32 loc) · 1.1 KB
/
inmoov_jaw.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
#include <VarSpeedServo.h>
VarSpeedServo myservo; // create servo object to control a servo
String inputString = "";
const int servoPin = 9; // the digital pin used for the servo
void setup() {
Serial.begin(128000);
myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object
myservo.write(50, 255, true); // set the initial position of the servo, as fast as possible, wait until done
}
void loop() {
signed int receivedValue;
signed int newValue;
if (Serial.available()) {
inputString = Serial.readStringUntil('!');
receivedValue = inputString.toInt();
if (receivedValue == 1) {
while (receivedValue == 1) {
myservo.write(50, 230, true); // move the servo to 180, slow speed, wait until done
myservo.write(180, 255, true);
if (Serial.available()) {
inputString = Serial.readStringUntil('!');
newValue = inputString.toInt();
if (newValue == 0 || newValue == 1) {
receivedValue = newValue;
}
}
}
} else if (receivedValue == 0) {
myservo.write(50, 255, true);
}
}
}