2014-git-work/arduino/ServoSetMicroseconds/ServoSetMicroseconds.ino
2012-08-28 22:52:01 +09:00

33 lines
526 B
C++

#include <Servo.h>
Servo servo1;
Servo servo2;
void setup() {
servo1.attach(9);
servo2.attach(10);
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;
}
}
}