#include <Arduino.h>

// The joystick has a pushbutton plus two analog axes.
const uint8_t SWITCH_PIN = 2;
// A0 reads the X-axis voltage; A1 below reads the Y-axis voltage.
const uint8_t X_PIN = A0;
const uint8_t Y_PIN = A1;

// Enable the switch pull-up and open Serial Monitor.
void setup() {
  pinMode(SWITCH_PIN, INPUT_PULLUP);
  // Use 9600 baud in PlatformIO Monitor to read the text.
  Serial.begin(9600);
}

// Print one snapshot of the switch state and both analog axes.
void loop() {
  Serial.print("Switch: ");
  // Switch = HIGH when released, LOW when pressed because of INPUT_PULLUP.
  Serial.println(digitalRead(SWITCH_PIN));
  Serial.print("X-axis: ");
  // On a Mega, analogRead() normally returns 0–1023 for the input voltage.
  Serial.println(analogRead(X_PIN));
  Serial.print("Y-axis: ");
  Serial.println(analogRead(Y_PIN));
  // Print a blank line to separate each group of readings.
  Serial.println();
  delay(500);
}
