const int VRx = A0; // Analog pin for X-axis const int VRy = A1; // Analog pin for Y-axis const int SW = D2; // Digital pin for Joystick button void setup() { Serial.begin(9600); pinMode(VRx, INPUT); pinMode(VRy, INPUT); pinMode(SW, INPUT_PULLUP); } void loop() { int xPosition = analogRead(VRx); int yPosition = analogRead(VRy); int buttonState = digitalRead(SW); // Send the joystick positions and button state via serial //Serial.print(" X:"); Serial.print(xPosition); Serial.print(" "); Serial.print(yPosition); Serial.print(" "); Serial.println(buttonState); delay(100); // Small delay to avoid flooding the serial communication }