// Pin untuk joystick
const int joystick1X = A0;
const int joystick1Y = A1;
const int joystick1SW = 2;
const int joystick2X = A2;
const int joystick2Y = A3;
const int joystick2SW = 3;
// Pin untuk tombol kecil
const int buttonSmall1 = 4;
const int buttonSmall2 = 5;
// Pin untuk tombol besar
const int buttonBig1 = 6;
const int buttonBig2 = 7;
const int buttonBig3 = 8;
const int buttonBig4 = 9;
void setup() {
Serial.begin(9600);
// Mengatur tombol sebagai input
pinMode(joystick1SW, INPUT_PULLUP);
pinMode(joystick2SW, INPUT_PULLUP);
pinMode(buttonSmall1, INPUT_PULLUP);
pinMode(buttonSmall2, INPUT_PULLUP);
pinMode(buttonBig1, INPUT_PULLUP);
pinMode(buttonBig2, INPUT_PULLUP);
pinMode(buttonBig3, INPUT_PULLUP);
pinMode(buttonBig4, INPUT_PULLUP);
}
void loop() {
// Membaca nilai joystick 1
int joystick1XValue = analogRead(joystick1X);
int joystick1YValue = analogRead(joystick1Y);
bool joystick1SWState = digitalRead(joystick1SW);
// Membaca nilai joystick 2
int joystick2XValue = analogRead(joystick2X);
int joystick2YValue = analogRead(joystick2Y);
bool joystick2SWState = digitalRead(joystick2SW);
// Membaca status tombol kecil
bool buttonSmall1State = digitalRead(buttonSmall1);
bool buttonSmall2State = digitalRead(buttonSmall2);
// Membaca status tombol besar
bool buttonBig1State = digitalRead(buttonBig1);
bool buttonBig2State = digitalRead(buttonBig2);
bool buttonBig3State = digitalRead(buttonBig3);
bool buttonBig4State = digitalRead(buttonBig4);
// Mengirim data ke Serial Monitor
Serial.print("Joystick 1 - X: ");
Serial.print(joystick1XValue);
Serial.print(" | Y: ");
Serial.print(joystick1YValue);
Serial.print(" | Button: ");
Serial.println(joystick1SWState == LOW ? "Pressed" : "Released");
Serial.print("Joystick 2 - X: ");
Serial.print(joystick2XValue);
Serial.print(" | Y: ");
Serial.print(joystick2YValue);
Serial.print(" | Button: ");
Serial.println(joystick2SWState == LOW ? "Pressed" : "Released");
Serial.print("Button Small 1: ");
Serial.println(buttonSmall1State == LOW ? "Pressed" : "Released");
Serial.print("Button Small 2: ");
Serial.println(buttonSmall2State == LOW ? "Pressed" : "Released");
Serial.print("Button Big 1: ");
Serial.println(buttonBig1State == LOW ? "Pressed" : "Released");
Serial.print("Button Big 2: ");
Serial.println(buttonBig2State == LOW ? "Pressed" : "Released");
Serial.print("Button Big 3: ");
Serial.println(buttonBig3State == LOW ? "Pressed" : "Released");
Serial.print("Button Big 4: ");
Serial.println(buttonBig4State == LOW ? "Pressed" : "Released");
delay(2000
); // Delay untuk memperlambat pembacaan
}