/* receive signal from Processing, via SoftwareSerial * control servomotor */ #include #include Servo servo;//サーボのインスタンス SoftwareSerial mySerial = SoftwareSerial(0, 1);//rx,tx (ATtiny44) const int servoPin = 5; // the pin that the servo is attached to void setup() { //サーボの信号線を servoPin に接続 servo.attach(servoPin); // initialize the serial communication: mySerial.begin(9600); delay(200); } void loop() { byte serialIn; // check if data has been sent from the computer: if (mySerial.available()) { // read the most recent byte (which will be from 0 to 255): serialIn = mySerial.read(); //map()を使ってセンサ読取り値を角度(回転速度)に変換 int servospeed=map(serialIn,0,255,10,170); // set the serbospeed of the servo motor: servo.write(servospeed); // delay(200); } }