#include <Servo.h>
int ledPin = 13;
int xPin = A0;
int yPin = A1;
int btnPin = 2;
int xValue;
int yValue;
int btnValue;
int xServoPin = 9;
int yServoPin = 10;
int xServoPos;
int yServoPos;
Servo xServo;
Servo yServo;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
pinMode(btnPin, INPUT_PULLUP);
xServo.attach(xServoPin);
yServo.attach(yServoPin);
}
void loop() {
xValue = analogRead(xPin);
yValue = analogRead(yPin);
btnValue = digitalRead(btnPin);
// target = map(sourse, lowSourse, highSourse, lowTarget, highTarget)
xServoPos = map(xValue, 0, 1023, 0, 180);
yServoPos = map(yValue, 0, 1023, 0, 180);
xServo.write(xServoPos);
yServo.write(yServoPos);
if (btnValue == LOW) {
digitalWrite(ledPin, HIGH);
}
if (btnValue == HIGH) {
digitalWrite(ledPin, LOW);
}
}