#include <Servo.h>
const int VX = A0;
const int VY = A1;
const int R = 6;
const int G = 7;
const int B = 8;
const int S1 = 3;
const int S2 = 5;
Servo servo1;
Servo servo2;
void setup()
// put your setup code here, to run once:
pinMode(R, OUTPUT);
pinMode(G, OUTPUT );
pinMode(B, OUTPUT);
servo1.attach(S1);
servo2.attach(S2);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int xValue = analogRead(VX);
int yValue = analogRead(VY);
int xAngle = map(xValue, 0, 1023, 0, 180);
int yAngle = map(yValue, 0, 1023, 0, 180);
// Putar servo motor sesuai sudut yang dihasilkan
servo1.write(xAngle);
servo2.write(yAngle);
// Tampilkan data di Serial Monitor pada Arduino IDE
Serial.print("Joystick: ");
Serial.print(xValue);
Serial.print(", ");
Serial.print(yValue);
Serial.print(" => Servo Motor: ");
Serial.print(xAngle);
Serial.print("°, ");
Serial.println(yAngle);
while(true) {
digitalWrite(R, HIGH);
delay(500);
digitalWrite(R, LOW);
}
}