2012-08-28 22:52:01 +09:00
|
|
|
#include <Servo.h>
|
|
|
|
|
|
|
|
Servo servo1;
|
|
|
|
Servo servo2;
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
servo1.attach(9);
|
|
|
|
servo2.attach(10);
|
|
|
|
Serial.begin(9600);
|
2013-10-24 01:41:45 +09:00
|
|
|
Serial.println("format : [0-180][ab]");
|
2012-08-28 22:52:01 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
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':
|
2013-10-24 01:41:45 +09:00
|
|
|
Serial.print("Servo(9) :");
|
|
|
|
Serial.println(v);
|
2012-08-28 22:52:01 +09:00
|
|
|
servo1.write(v);
|
|
|
|
v = 0;
|
|
|
|
break;
|
|
|
|
case 'b':
|
2013-10-24 01:41:45 +09:00
|
|
|
Serial.print("Servo(10):");
|
|
|
|
Serial.println(v);
|
2012-08-28 22:52:01 +09:00
|
|
|
servo2.write(v);
|
|
|
|
v = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|