36 lines
602 B
Arduino
36 lines
602 B
Arduino
|
#include <Servo.h>
|
||
|
|
||
|
Servo servo1;
|
||
|
Servo servo2;
|
||
|
|
||
|
void setup() {
|
||
|
servo1.attach(9,1450-570,1450+570);
|
||
|
servo2.attach(10,1535-780,1535+780);
|
||
|
servo1.write(90);
|
||
|
servo2.write(90);
|
||
|
Serial.begin(9600);
|
||
|
Serial.print("format : [0-9]+[ab]");
|
||
|
}
|
||
|
|
||
|
void loop() {
|
||
|
static int v = 0;
|
||
|
|
||
|
if ( Serial.available()) {
|
||
|
char ch = Serial.read();
|
||
|
|
||
|
switch(ch) {
|
||
|
case '0'...'9':
|
||
|
v = v * 10 + ch - '0';
|
||
|
break;
|
||
|
case 'a':
|
||
|
servo1.writeMicroseconds(v);
|
||
|
v = 0;
|
||
|
break;
|
||
|
case 'b':
|
||
|
servo2.writeMicroseconds(v);
|
||
|
v = 0;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|