2014-git-work/arduino/ServoSet/ServoSet.ino

38 lines
632 B
Arduino
Raw Normal View History

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);
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':
Serial.print("Servo(9) :");
Serial.println(v);
2012-08-28 22:52:01 +09:00
servo1.write(v);
v = 0;
break;
case 'b':
Serial.print("Servo(10):");
Serial.println(v);
2012-08-28 22:52:01 +09:00
servo2.write(v);
v = 0;
break;
}
}
}