/*
*
* 鍙岃酱鎸夐敭鎽囨潌
*/
#include <Servo.h> //璋冪敤鑸垫満搴?
#define pinx1 A0
#define piny1 A1
#define pinx2 A2
#define piny2 A3
Servo myservo_2; //搴曞骇2鍙峰彛锛?180
int pos2 = 0;
int x1 =0;
Servo myservo_3; //搴曞骇2鍙峰彛锛?180
int pos3 = 0;
int y1 =0;
Servo myservo_4; //搴曞骇2鍙峰彛锛?180
int pos4 = 0;
int x2 =0;
Servo myservo_5; //搴曞骇2鍙峰彛锛?180
int pos5 = 0;
int y2 =0;
void setup()
{
myservo_2.attach(2); // 璁剧疆鑸垫満鎺у埗閽堣剼鎺ユ暟瀛?2寮曡剼
myservo_3.attach(3);
myservo_4.attach(4);
myservo_5.attach(5);
Serial.begin(9600);
}
void loop()
{
x1 = analogRead(pinx1);
Serial.print("X: ");
Serial.print(x1);
y1 = analogRead(piny1);
Serial.print("Y: ");
Serial.print(y1);
x2 = analogRead(pinx2);
Serial.print("X2: ");
Serial.print(x2);
y2 = analogRead(piny2);
Serial.print("Y2: ");
Serial.println(y2);
//2=搴曞骇
pos2 = map(x1, 1023, 0, 0, 180);
myservo_2.write(pos2); //杞姩
delay(10);//寤惰繜5ms
pos3 = map(y1, 1023, 0, 0, 180);//鍋氳搴︽槧灏?
myservo_3.write(pos3); //杞姩
delay(10);//寤惰繜5ms
pos4 = map(x2, 0, 1023, 45, 135);//鍋氳搴︽槧灏?
myservo_4.write(pos4); //杞姩
delay(10);//寤惰繜5ms
pos5 = map(y2, 0, 1023, 0, 180);//鍋氳搴︽槧灏?
myservo_5.write(pos5); //杞姩
delay(10);//寤惰繜5ms
}